• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1@c This file is part of the GNU gettext manual.
2@c Copyright (C) 1995-2020 Free Software Foundation, Inc.
3@c See the file gettext.texi for copying conditions.
4
5@node Python
6@subsection Python
7@cindex Python
8
9@table @asis
10@item RPMs
11python
12
13@item Ubuntu packages
14python
15
16@item File extension
17@code{py}
18
19@item String syntax
20@code{'abc'}, @code{u'abc'}, @code{r'abc'}, @code{ur'abc'},
21@*@code{"abc"}, @code{u"abc"}, @code{r"abc"}, @code{ur"abc"},
22@*@code{'''abc'''}, @code{u'''abc'''}, @code{r'''abc'''}, @code{ur'''abc'''},
23@*@code{"""abc"""}, @code{u"""abc"""}, @code{r"""abc"""}, @code{ur"""abc"""}
24
25@item gettext shorthand
26@code{_('abc')} etc.
27
28@item gettext/ngettext functions
29@code{gettext.gettext}, @code{gettext.dgettext},
30@code{gettext.ngettext}, @code{gettext.dngettext},
31also @code{ugettext}, @code{ungettext}
32
33@item textdomain
34@code{gettext.textdomain} function, or
35@code{gettext.install(@var{domain})} function
36
37@item bindtextdomain
38@code{gettext.bindtextdomain} function, or
39@code{gettext.install(@var{domain},@var{localedir})} function
40
41@item setlocale
42not used by the gettext emulation
43
44@item Prerequisite
45@code{import gettext}
46
47@item Use or emulate GNU gettext
48emulate
49
50@item Extractor
51@code{xgettext}
52
53@item Formatting with positions
54@code{'...%(ident)d...' % @{ 'ident': value @}}
55
56@item Portability
57fully portable
58
59@item po-mode marking
60---
61@end table
62
63An example is available in the @file{examples} directory: @code{hello-python}.
64
65A note about format strings: Python supports format strings with unnamed
66arguments, such as @code{'...%d...'}, and format strings with named arguments,
67such as @code{'...%(ident)d...'}.  The latter are preferable for
68internationalized programs, for two reasons:
69
70@itemize @bullet
71@item
72When a format string takes more than one argument, the translator can provide
73a translation that uses the arguments in a different order, if the format
74string uses named arguments.  For example, the translator can reformulate
75@smallexample
76"'%(volume)s' has only %(freespace)d bytes free."
77@end smallexample
78@noindent
79to
80@smallexample
81"Only %(freespace)d bytes free on '%(volume)s'."
82@end smallexample
83@noindent
84Additionally, the identifiers also provide some context to the translator.
85
86@item
87In the context of plural forms, the format string used for the singular form
88does not use the numeric argument in many languages.  Even in English, one
89prefers to write @code{"one hour"} instead of @code{"1 hour"}.  Omitting
90individual arguments from format strings like this is only possible with
91the named argument syntax.  (With unnamed arguments, Python -- unlike C --
92verifies that the format string uses all supplied arguments.)
93@end itemize
94