Next: Java, Previous: C, C++, Objective C, Up: Individual Programming Languages [Contents][Index]
python
python
py
'abc'
, u'abc'
, r'abc'
, ur'abc'
,
"abc"
, u"abc"
, r"abc"
, ur"abc"
,
'''abc'''
, u'''abc'''
, r'''abc'''
, ur'''abc'''
,
"""abc"""
, u"""abc"""
, r"""abc"""
, ur"""abc"""
_('abc')
etc.
gettext.gettext
, gettext.dgettext
,
gettext.ngettext
, gettext.dngettext
,
also ugettext
, ungettext
gettext.textdomain
function, or
gettext.install(domain)
function
gettext.bindtextdomain
function, or
gettext.install(domain,localedir)
function
not used by the gettext emulation
import gettext
emulate
xgettext
'...%(ident)d...' % { 'ident': value }
'...{ident}...'.format(ident=value)
(see PEP 3101)
fully portable
—
An example is available in the examples directory: hello-python
.
A note about format strings: Python supports format strings with unnamed
arguments, such as '...%d...'
, and format strings with named arguments,
such as '...%(ident)d...'
. The latter are preferable for
internationalized programs, for two reasons:
"'%(volume)s' has only %(freespace)d bytes free."
to
"Only %(freespace)d bytes free on '%(volume)s'."
Additionally, the identifiers also provide some context to the translator.
"one hour"
instead of "1 hour"
. Omitting
individual arguments from format strings like this is only possible with
the named argument syntax. (With unnamed arguments, Python – unlike C –
verifies that the format string uses all supplied arguments.)
Next: Java, Previous: C, C++, Objective C, Up: Individual Programming Languages [Contents][Index]