gettext: Python
1
1 15.5.4 Python
1 -------------
1
1 RPMs
1 python
1
1 File extension
1 ‘py’
1
1 String syntax
1 ‘'abc'’, ‘u'abc'’, ‘r'abc'’, ‘ur'abc'’,
1 ‘"abc"’, ‘u"abc"’, ‘r"abc"’, ‘ur"abc"’,
1 ‘'''abc'''’, ‘u'''abc'''’, ‘r'''abc'''’, ‘ur'''abc'''’,
1 ‘"""abc"""’, ‘u"""abc"""’, ‘r"""abc"""’, ‘ur"""abc"""’
1
1 gettext shorthand
1 ‘_('abc')’ etc.
1
1 gettext/ngettext functions
1 ‘gettext.gettext’, ‘gettext.dgettext’, ‘gettext.ngettext’,
1 ‘gettext.dngettext’, also ‘ugettext’, ‘ungettext’
1
1 textdomain
1 ‘gettext.textdomain’ function, or ‘gettext.install(DOMAIN)’
1 function
1
1 bindtextdomain
1 ‘gettext.bindtextdomain’ function, or
1 ‘gettext.install(DOMAIN,LOCALEDIR)’ function
1
1 setlocale
1 not used by the gettext emulation
1
1 Prerequisite
1 ‘import gettext’
1
1 Use or emulate GNU gettext
1 emulate
1
1 Extractor
1 ‘xgettext’
1
1 Formatting with positions
1 ‘'...%(ident)d...' % { 'ident': value }’
1
1 Portability
1 fully portable
1
1 po-mode marking
1 —
1
1 An example is available in the ‘examples’ directory: ‘hello-python’.
1
1 A note about format strings: Python supports format strings with
1 unnamed arguments, such as ‘'...%d...'’, and format strings with named
1 arguments, such as ‘'...%(ident)d...'’. The latter are preferable for
1 internationalized programs, for two reasons:
1
1 • When a format string takes more than one argument, the translator
1 can provide a translation that uses the arguments in a different
1 order, if the format string uses named arguments. For example, the
1 translator can reformulate
1 "'%(volume)s' has only %(freespace)d bytes free."
1 to
1 "Only %(freespace)d bytes free on '%(volume)s'."
1 Additionally, the identifiers also provide some context to the
1 translator.
1
1 • In the context of plural forms, the format string used for the
1 singular form does not use the numeric argument in many languages.
1 Even in English, one prefers to write ‘"one hour"’ instead of ‘"1
1 hour"’. Omitting individual arguments from format strings like
1 this is only possible with the named argument syntax. (With
1 unnamed arguments, Python – unlike C – verifies that the format
1 string uses all supplied arguments.)
1