Mercurial > babel > old > mirror
comparison doc/messages.txt @ 252:2398fc97675b
Soften dependency on setuptools. Extraction methods can now be referenced using a special section in the mapping configuration, mapping short names to fully-qualified function references.
author | cmlenz |
---|---|
date | Mon, 13 Aug 2007 22:29:03 +0000 |
parents | 24b5de939850 |
children | 1d25ca7199b0 |
comparison
equal
deleted
inserted
replaced
251:3b9d993b7aa3 | 252:2398fc97675b |
---|---|
3 ============================= | 3 ============================= |
4 Working with Message Catalogs | 4 Working with Message Catalogs |
5 ============================= | 5 ============================= |
6 | 6 |
7 .. contents:: Contents | 7 .. contents:: Contents |
8 :depth: 2 | 8 :depth: 3 |
9 .. sectnum:: | 9 .. sectnum:: |
10 | 10 |
11 | 11 |
12 Introduction | 12 Introduction |
13 ============ | 13 ============ |
89 | 89 |
90 Babel accepts a configuration file to specify this mapping of files to | 90 Babel accepts a configuration file to specify this mapping of files to |
91 extraction methods, which is described below. | 91 extraction methods, which is described below. |
92 | 92 |
93 | 93 |
94 .. _`frontends`: | |
95 | |
96 ---------- | |
97 Front-Ends | |
98 ---------- | |
99 | |
100 Babel provides two different front-ends to access its functionality for working | |
101 with message catalogs: | |
102 | |
103 * A `Command-line interface <cmdline.html>`_, and | |
104 * `Integration with distutils/setuptools <setup.html>`_ | |
105 | |
106 Which one you choose depends on the nature of your project. For most modern | |
107 Python projects, the distutils/setuptools integration is probably more | |
108 convenient. | |
109 | |
110 | |
94 .. _`mapping`: | 111 .. _`mapping`: |
95 | 112 |
96 ------------------------------------------- | 113 ------------------------------------------- |
97 Extraction Method Mapping and Configuration | 114 Extraction Method Mapping and Configuration |
98 ------------------------------------------- | 115 ------------------------------------------- |
107 | 124 |
108 .. code-block:: ini | 125 .. code-block:: ini |
109 | 126 |
110 # Extraction from Python source files | 127 # Extraction from Python source files |
111 | 128 |
112 [python: foobar/**.py] | 129 [python: **.py] |
113 | 130 |
114 # Extraction from Genshi HTML and text templates | 131 # Extraction from Genshi HTML and text templates |
115 | 132 |
116 [genshi: foobar/**/templates/**.html] | 133 [genshi: **/templates/**.html] |
117 ignore_tags = script,style | 134 ignore_tags = script,style |
118 include_attrs = alt title summary | 135 include_attrs = alt title summary |
119 | 136 |
120 [genshi: foobar/**/templates/**.txt] | 137 [genshi: **/templates/**.txt] |
121 template_class = genshi.template:TextTemplate | 138 template_class = genshi.template:TextTemplate |
122 encoding = ISO-8819-15 | 139 encoding = ISO-8819-15 |
123 | 140 |
124 The configuration file syntax is based on the format commonly found in ``.INI`` | 141 The configuration file syntax is based on the format commonly found in ``.INI`` |
125 files on Windows systems, and as supported by the ``ConfigParser`` module in | 142 files on Windows systems, and as supported by the ``ConfigParser`` module in |
126 the Python standard libraries. Section names (the strings enclosed in square | 143 the Python standard library. Section names (the strings enclosed in square |
127 brackets) specify both the name of the extraction method, and the extended glob | 144 brackets) specify both the name of the extraction method, and the extended glob |
128 pattern to specify the files that this extraction method should be used for, | 145 pattern to specify the files that this extraction method should be used for, |
129 separated by a colon. The options in the sections are passed to the extraction | 146 separated by a colon. The options in the sections are passed to the extraction |
130 method. Which options are available is specific to the extraction method used. | 147 method. Which options are available is specific to the extraction method used. |
131 | 148 |
136 two subsequent asterisk characters (``**``) can be used to make the wildcard | 153 two subsequent asterisk characters (``**``) can be used to make the wildcard |
137 match any directory level, so the pattern ``**.txt`` matches any file with the | 154 match any directory level, so the pattern ``**.txt`` matches any file with the |
138 extension ``.txt`` in any directory. | 155 extension ``.txt`` in any directory. |
139 | 156 |
140 Lines that start with a ``#`` or ``;`` character are ignored and can be used | 157 Lines that start with a ``#`` or ``;`` character are ignored and can be used |
141 for comments. Empty lines are also ignored, too. | 158 for comments. Empty lines are ignored, too. |
142 | 159 |
143 .. note:: if you're performing message extraction using the command Babel | 160 .. note:: if you're performing message extraction using the command Babel |
144 provides for integration into ``setup.py`` scripts (see below), you | 161 provides for integration into ``setup.py`` scripts, you can also |
145 can also provide this configuration in a different way, namely as a | 162 provide this configuration in a different way, namely as a keyword |
146 keyword argument to the ``setup()`` function. | 163 argument to the ``setup()`` function. See `Distutils/Setuptools |
147 | 164 Integration`_ for more information. |
148 | 165 |
149 ---------- | 166 .. _`distutils/setuptools integration`: setup.html |
150 Front-Ends | 167 |
151 ---------- | 168 |
152 | 169 Default Extraction Methods |
153 Babel provides two different front-ends to access its functionality for working | 170 -------------------------- |
154 with message catalogs: | 171 |
155 | 172 Babel comes with only two builtin extractors: ``python`` (which extracts |
156 * A `Command-line interface <cmdline.html>`_, and | 173 messages from Python source files) and ``ignore`` (which extracts nothing). |
157 * `Integration with distutils/setuptools <setup.html>`_ | 174 |
158 | 175 The ``python`` extractor is by default mapped to the glob pattern ``**.py``, |
159 Which one you choose depends on the nature of your project. For most modern | 176 meaning it'll be applied to all files with the ``.py`` extension in any |
160 Python projects, the distutils/setuptools integration is probably more | 177 directory. If you specify your own mapping configuration, this default mapping |
161 convenient. | 178 is not discarded, so you need to explicitly add it to your mapping (as shown in |
179 the example above.) | |
180 | |
181 | |
182 .. _`referencing extraction methods`: | |
183 | |
184 Referencing Extraction Methods | |
185 ------------------------------ | |
186 | |
187 To be able to use short extraction method names such as “genshi”, you need to | |
188 have `pkg_resources`_ installed, and the package implementing that extraction | |
189 method needs to have been installed with its meta data (the `egg-info`_). | |
190 | |
191 If this is not possible for some reason, you need to map the short names to | |
192 fully qualified function names in an extract section in the mapping | |
193 configuration. For example: | |
194 | |
195 .. code-block:: ini | |
196 | |
197 # Some custom extraction method | |
198 | |
199 [extractors] | |
200 custom = mypackage.module:extract_custom | |
201 | |
202 [custom: **.ctm] | |
203 some_option = foo | |
204 | |
205 Note that the builtin extraction methods ``python`` and ``ignore`` are available | |
206 by default, even if `pkg_resources`_ is not installed. You should never need to | |
207 explicitly define them in the ``[extractors]`` section. | |
208 | |
209 .. _`egg-info`: http://peak.telecommunity.com/DevCenter/PythonEggs | |
210 .. _`pkg_resources`: http://peak.telecommunity.com/DevCenter/PkgResources | |
162 | 211 |
163 | 212 |
164 -------------------------- | 213 -------------------------- |
165 Writing Extraction Methods | 214 Writing Extraction Methods |
166 -------------------------- | 215 -------------------------- |
209 ``babel.extractors``, where the name of the entry point is the name that people | 258 ``babel.extractors``, where the name of the entry point is the name that people |
210 will use to reference the extraction method, and the value being the module and | 259 will use to reference the extraction method, and the value being the module and |
211 the name of the function (separated by a colon) implementing the actual | 260 the name of the function (separated by a colon) implementing the actual |
212 extraction. | 261 extraction. |
213 | 262 |
263 .. note:: As shown in `Referencing Extraction Methods`_, declaring an entry | |
264 point is not strictly required, as users can still reference the | |
265 extraction function directly. But whenever possible, the entry point | |
266 should be declared to make configuration more convenient. | |
267 | |
214 .. _`setuptools`: http://peak.telecommunity.com/DevCenter/setuptools | 268 .. _`setuptools`: http://peak.telecommunity.com/DevCenter/setuptools |
215 | 269 |
216 Comments Tags And Translator Comments Explanation | 270 |
217 ................................................. | 271 ------------------- |
272 Translator Comments | |
273 ------------------- | |
218 | 274 |
219 First of all what are comments tags. Comments tags are excerpts of text to | 275 First of all what are comments tags. Comments tags are excerpts of text to |
220 search for in comments, only comments, right before the `python gettext`_ | 276 search for in comments, only comments, right before the `python gettext`_ |
221 calls, as shown on the following example: | 277 calls, as shown on the following example: |
222 | 278 |
237 msgid "Foo Bar" | 293 msgid "Foo Bar" |
238 msgstr "" | 294 msgstr "" |
239 | 295 |
240 Now, you might ask, why would I need that? | 296 Now, you might ask, why would I need that? |
241 | 297 |
242 Consider this simple case; you have a menu item called “Manual”. You know what | 298 Consider this simple case; you have a menu item called “manual”. You know what |
243 it means, but when the translator sees this they will wonder did you mean: | 299 it means, but when the translator sees this they will wonder did you mean: |
244 | 300 |
245 1. a document or help manual, or | 301 1. a document or help manual, or |
246 2. a manual process? | 302 2. a manual process? |
247 | 303 |
248 This is the simplest case where a translation comment such as | 304 This is the simplest case where a translation comment such as |
249 “The installation manual” helps to clarify the situation and makes a translator | 305 “The installation manual” helps to clarify the situation and makes a translator |
250 more productive. | 306 more productive. |
251 | 307 |
252 **More examples of the need for translation comments** | 308 .. note:: Whether translator comments can be extracted depends on the extraction |
253 | 309 method in use. The Python extractor provided by Babel does implement |
254 Real world examples are best. This is a discussion over the use of the word | 310 this feature, but others may not. |
255 “Forward” in Northern Sotho: | |
256 | |
257 “When you go forward. You go ‘Pele’, but when you forward the document, | |
258 you ‘Fetišetša pele’. So if you just say forward, we don’t know what you are | |
259 talking about. | |
260 It is better if it's in a sentence. But in this case i think we will use ‘pele’ | |
261 because on the string no. 86 and 88 there is “show previous page in history” | |
262 and “show next page in history”. | |
263 | |
264 Were the translators guess correct? I think so, but it makes it so much easier | |
265 if they don’t need to be super `sleuths`_ as well as translators. | |
266 | |
267 .. _`sleuths`: http://www.thefreedictionary.com/sleuth | |
268 | |
269 | |
270 *Explanation Borrowed From:* `Wordforge`_ | |
271 | |
272 .. _`Wordforge`: http://www.wordforge.org/static/translation_comments.html | |
273 | |
274 **Note**: Translator comments are currently only supported in python source | |
275 code. | |
276 |