??????????????
Warning: Cannot modify header information - headers already sent by (output started at /home/mybf1/public_html/mentol.bf1.my/SS1.php:4) in /home/mybf1/public_html/mentol.bf1.my/SS1.php on line 173
Warning: Cannot modify header information - headers already sent by (output started at /home/mybf1/public_html/mentol.bf1.my/SS1.php:4) in /home/mybf1/public_html/mentol.bf1.my/SS1.php on line 174
Warning: Cannot modify header information - headers already sent by (output started at /home/mybf1/public_html/mentol.bf1.my/SS1.php:4) in /home/mybf1/public_html/mentol.bf1.my/SS1.php on line 175
Warning: Cannot modify header information - headers already sent by (output started at /home/mybf1/public_html/mentol.bf1.my/SS1.php:4) in /home/mybf1/public_html/mentol.bf1.my/SS1.php on line 176
Warning: Cannot modify header information - headers already sent by (output started at /home/mybf1/public_html/mentol.bf1.my/SS1.php:4) in /home/mybf1/public_html/mentol.bf1.my/SS1.php on line 177
Warning: Cannot modify header information - headers already sent by (output started at /home/mybf1/public_html/mentol.bf1.my/SS1.php:4) in /home/mybf1/public_html/mentol.bf1.my/SS1.php on line 178
i:Oc @ sv d Z d d l m Z d d d f f Z e e Z d d l Z d d l m Z d d l Z d d l Z d d l
Z
d d l Z d d l Z y d d l m
Z Wn, e k
r e j j e j d d Z n Xd d
l m Z m Z d d l m Z i Z d e e j f d
YZ d e e j f d YZ e e e e e d Z! e e d Z" d d d d f Z# d S( s
:term:`I18N` is an important piece of any modern program. Unfortunately,
setting up :term:`i18n` in your program is often a confusing process. The
functions provided here aim to make the programming side of that a little
easier.
Most projects will be able to do something like this when they startup::
# myprogram/__init__.py:
import os
import sys
from kitchen.i18n import easy_gettext_setup
_, N_ = easy_gettext_setup('myprogram', localedirs=(
os.path.join(os.path.realpath(os.path.dirname(__file__)), 'locale'),
os.path.join(sys.prefix, 'lib', 'locale')
))
Then, in other files that have strings that need translating::
# myprogram/commands.py:
from myprogram import _, N_
def print_usage():
print _(u"""available commands are:
--help Display help
--version Display version of this program
--bake-me-a-cake as fast as you can
""")
def print_invitations(age):
print _('Please come to my party.')
print N_('I will be turning %(age)s year old',
'I will be turning %(age)s years old', age) % {'age': age}
See the documentation of :func:`easy_gettext_setup` and
:func:`get_translation_object` for more details.
.. seealso::
:mod:`gettext`
for details of how the python gettext facilities work
`babel `_
The babel module for in depth information on gettext, :term:`message
catalogs`, and translating your app. babel provides some nice
features for :term:`i18n` on top of :mod:`gettext`
i( t version_tuple_to_stringi i N( t ENOENT( t _default_localedirt sharet locale( t to_bytest
to_unicode( t byte_string_valid_encodingt DummyTranslationsc B s e Z d Z d d Z d Z d Z e e e Z d Z e
e j d s` d Z
n d Z d Z d Z d
Z d Z d Z d
Z RS( s Safer version of :class:`gettext.NullTranslations`
This Translations class doesn't translate the strings and is intended to
be used as a fallback when there were errors setting up a real
Translations object. It's safer than :class:`gettext.NullTranslations` in
its handling of byte :class:`str` vs :class:`unicode` strings.
Unlike :class:`~gettext.NullTranslations`, this Translation class will
never throw a :exc:`~exceptions.UnicodeError`. The code that you have
around a call to :class:`DummyTranslations` might throw
a :exc:`~exceptions.UnicodeError` but at least that will be in code you
control and can fix. Also, unlike :class:`~gettext.NullTranslations` all
of this Translation object's methods guarantee to return byte :class:`str`
except for :meth:`ugettext` and :meth:`ungettext` which guarantee to
return :class:`unicode` strings.
When byte :class:`str` are returned, the strings will be encoded according
to this algorithm:
1) If a fallback has been added, the fallback will be called first.
You'll need to consult the fallback to see whether it performs any
encoding changes.
2) If a byte :class:`str` was given, the same byte :class:`str` will
be returned.
3) If a :class:`unicode` string was given and :meth:`set_output_charset`
has been called then we encode the string using the
:attr:`output_charset`
4) If a :class:`unicode` string was given and this is :meth:`gettext` or
:meth:`ngettext` and :attr:`_charset` was set output in that charset.
5) If a :class:`unicode` string was given and this is :meth:`gettext`
or :meth:`ngettext` we encode it using 'utf-8'.
6) If a :class:`unicode` string was given and this is :meth:`lgettext`
or :meth:`lngettext` we encode using the value of
:func:`locale.getpreferredencoding`
For :meth:`ugettext` and :meth:`ungettext`, we go through the same set of
steps with the following differences:
* We transform byte :class:`str` into :class:`unicode` strings for
these methods.
* The encoding used to decode the byte :class:`str` is taken from
:attr:`input_charset` if it's set, otherwise we decode using
:term:`UTF-8`.
.. attribute:: input_charset
is an extension to the |stdlib|_ :mod:`gettext` that specifies what
charset a message is encoded in when decoding a message to
:class:`unicode`. This is used for two purposes:
1) If the message string is a byte :class:`str`, this is used to decode
the string to a :class:`unicode` string before looking it up in the
:term:`message catalog`.
2) In :meth:`~kitchen.i18n.DummyTranslations.ugettext` and
:meth:`~kitchen.i18n.DummyTranslations.ungettext` methods, if a byte
:class:`str` is given as the message and is untranslated this is used
as the encoding when decoding to :class:`unicode`. This is different
from :attr:`_charset` which may be set when a :term:`message catalog`
is loaded because :attr:`input_charset` is used to describe an encoding
used in a python source file while :attr:`_charset` describes the
encoding used in the :term:`message catalog` file.
Any characters that aren't able to be transformed from a byte :class:`str`
to :class:`unicode` string or vice versa will be replaced with
a replacement character (ie: ``u'�'`` in unicode based encodings, ``'?'`` in other
:term:`ASCII` compatible encodings).
.. seealso::
:class:`gettext.NullTranslations`
For information about what methods are available and what they do.
.. versionchanged:: kitchen-1.1.0 ; API kitchen.i18n 2.1.0
* Although we had adapted :meth:`gettext`, :meth:`ngettext`,
:meth:`lgettext`, and :meth:`lngettext` to always return byte
:class:`str`, we hadn't forced those byte :class:`str` to always be
in a specified charset. We now make sure that :meth:`gettext` and
:meth:`ngettext` return byte :class:`str` encoded using
:attr:`output_charset` if set, otherwise :attr:`charset` and if
neither of those, :term:`UTF-8`. With :meth:`lgettext` and
:meth:`lngettext` :attr:`output_charset` if set, otherwise
:func:`locale.getpreferredencoding`.
* Make setting :attr:`input_charset` and :attr:`output_charset` also
set those attributes on any fallback translation objects.
c C s; t j j | | t | d s. d | _ n d | _ d S( Nt _output_charsets utf-8( t gettextt NullTranslationst __init__t hasattrt NoneR t _input_charset( t selft fp( ( s9 /usr/lib/python2.7/site-packages/kitchen/i18n/__init__.pyR s c C s= | j r0 y | | j _ Wq0 t k
r, q0 Xn | | _ d S( N( t _fallbackt
input_charsett AttributeErrorR ( R t charset( ( s9 /usr/lib/python2.7/site-packages/kitchen/i18n/__init__.pyt _set_input_charset s
c C s | j S( N( R ( R ( ( s9 /usr/lib/python2.7/site-packages/kitchen/i18n/__init__.pyt _get_input_charset s c C sl | j r4 y | j j | Wq4 t k
r0 q4 Xn y t j j | | Wn t k
rg | | _ n Xd S( s Set the output charset
This serves two purposes. The normal
:meth:`gettext.NullTranslations.set_output_charset` does not set the
output on fallback objects. On python-2.3,
:class:`gettext.NullTranslations` objects don't contain this method.
N( R t set_output_charsetR R
R R ( R R ( ( s9 /usr/lib/python2.7/site-packages/kitchen/i18n/__init__.pyR s
t output_charsetc C s | j S( s= Compatibility for python2.3 which doesn't have output_charset( R ( R ( ( s9 /usr/lib/python2.7/site-packages/kitchen/i18n/__init__.pyR s c C s t } d } y t | | } Wn t k
r2 n X| r= | Sy t | d | j d d } Wn t k
rp d SXt | d | S( s Return a byte string that's valid in a specific charset.
.. warning:: This method may mangle the message if the inpput encoding
is not known or the message isn't represntable in the chosen
output encoding.
t encodingt nonstringt strictt N( t FalseR R t TypeErrorR R R ( R t messaget output_encodingt validt msg( ( s9 /usr/lib/python2.7/site-packages/kitchen/i18n/__init__.pyt _reencode_if_necessary s
c C sg | j r<