137 | | [FIXME: add more details about msg extraction from other files] |
| 138 | But Babel only does extract from Python scripts by default. To extract messages from Genshi templates as well, you'll have to declare the needed extractors in `setup.py`: |
| 139 | {{{#!diff |
| 140 | diff --git a/setup.py b/setup.py |
| 141 | --- a/setup.py |
| 142 | +++ b/setup.py |
| 143 | @@ -34,6 +35,21 @@ |
| 144 | |
| 145 | from setuptools import find_packages, setup |
| 146 | |
| 147 | +extra = {} |
| 148 | +try: |
| 149 | + extractors = [ |
| 150 | + ('**.py', 'python', None), |
| 151 | + ('**/templates/**.html', 'genshi', None), |
| 152 | + ('**/templates/**.txt', 'genshi', { |
| 153 | + 'template_class': 'genshi.template:TextTemplate' |
| 154 | + }), |
| 155 | + ] |
| 156 | + extra['message_extractors'] = { |
| 157 | + 'foo': extractors, |
| 158 | + } |
| 159 | +except ImportError: |
| 160 | + pass |
| 161 | + |
| 162 | setup( |
| 163 | name = 'foo', |
| 164 | version = '0.12', |
| 165 | @@ -53,6 +69,7 @@ |
| 166 | 'templates/*.txt', |
| 167 | 'htdocs/*.*', |
| 168 | 'htdocs/css/*.*', |
| 169 | + 'locale/*/LC_MESSAGES/*.mo', |
| 170 | ] |
| 171 | }, |
| 172 | install_requires = [ |
| 173 | @@ -96,4 +113,5 @@ |
| 174 | ] |
| 175 | }, |
| 176 | test_suite = '<path>.tests', |
| 177 | + **extra |
| 178 | ) |
| 179 | }}} |
| 180 | |
| 181 | ==== i18n for Java scripts ==== |
| 182 | {{{#!comment |
| 183 | This is taken largely from studying code in http://trac-hacks.org/wiki/TracTicketTemplatePlugin. Some conclusions may be plain wrong, since I had not time to carefully investigate and verify this. |
| 184 | }}} |
| 185 | Note: This section has some preliminary content. Please handle with care and contribute your/any better knowledge on the subject. |
| 186 | |
| 187 | You'll have to start with marking text to get it handled by translation helper programs, so a line that was |
| 188 | {{{ |
| 189 | var answer = confirm("Submit ticket?"); |
| 190 | }}} |
| 191 | before, will read like |
| 192 | {{{ |
| 193 | var answer = confirm("${_('Submit ticket?')}"); |
| 194 | }}} |
| 195 | afterwards. |
| 196 | |
| 197 | Wrap whole code containing marked text with a text replacement function like |
| 198 | {{{ |
| 199 | $.fn.extend({ |
| 200 | foo: function() { |
| 201 | function _(message){ return message; } |
| 202 | messages = [ |
| 203 | _('Submit ticket?'), |
| 204 | ] |
| 205 | |
| 206 | ... |
| 207 | |
| 208 | function onFormSubmit(evt) { |
| 209 | if (evt.type == "submit"){ |
| 210 | // confirm to save |
| 211 | if ($("#ticket_status").length == 0 || $.trim($("#ticket_status$ |
| 212 | var answer = confirm("${_('Submit ticket?')}"); |
| 213 | if (!answer) { |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | ... |
| 221 | |
| 222 | }); |
| 223 | |
| 224 | }}} |
| 225 | |
| 226 | To extract messages from Java scripts, you'll have to extend `setup.py` like shown in previous chapter for Genshi templates, but declare yet another extractor by listing it within the `extractors` list: |
| 227 | {{{ |
| 228 | ('**/templates/**.js', 'javascript', None), |
| 229 | }}} |