[ckan-discuss] Translation of custom templates?
Sean Hammond
sean.hammond at okfn.org
Fri Dec 21 20:03:27 GMT 2012
> I was more thinking in the context of translating our extra_template's.
>
> We add our own theme by overriding some templates by using:
> extra_template_paths = %(here)s/theme/templates
>
> And if i introduce additional strings there, it would be nice to keep
> those translations there allso somehow.
>
> Currently it works just great if we don't change any of the
> "default"-strings in the templates, then the translation system picks
> those up just fine, but if i would like to add additional strings or
> change some of the existing they don't get translated.
>
> It would be great if there were a translation section of the theming
> help.
Hey, did you find a solution to this?
I think you might be able to do something along these lines:
The "message extractors" defined in CKAN's setup.py file is a list of
dictionaries that define where the translation tools should look for
strings to be translated. So add a new entry with the path(s) to your
custom template files. Example:
'/path/to/your/extra/template/path': [
('**.html', 'ckan', None),
]},
Run the `python setup.py extract_messages` command to extract all the
marked-for-translation strings from your source files into the ckan.pot
file. This uses the "message extractors" from setup.py to decide what
files to extract strings from.
Now you have an upddated ckan.pot file that contains all the strings
from CKAN, plus the strings from your custom templates.
Now run `python setup.py update_catalog --no-fuzzy-matching` to update
the ckan.po files (which are the files containing the translations of the
strings into different languages) with the new strings from the
ckan.post file.
Now if you look in one of the po files, e.g.
ckan/i18n/de/LC_MESSAGES/ckan.po, you should find the strings from your
custom templates in there (as well as all the strings from CKAN core,
and their translations).
Now you need to use a suitable po file editor to edit all the ckan.po
files, adding in the translations for your custom strings. We use
Transifex.com for this, and we do all our editing in their web
interface.
Once you've finished editing the po files, run the
`python setup.py compile_catalog` command to compile the ckan.po files
into the ckan.mo files. The mo files are the files that CKAN actually
reads when displaying strings to the user.
Now you should be able to run CKAN and see your translations.
You might find it useful to read the CKAN Release Process, which
describes how we handle the translation files when doing a CKAN release:
https://github.com/okfn/ckan/wiki/Release-Process
I _believe_ CKAN's i18n setup is just a plain Pylons i18n setup, so you
might also find this useful:
http://pylonsbook.com/en/1.1/internationalization-and-localization.html
I'd be interested to know how you get on with this and if you find a
solution that works, as this would be a good thing to add to the CKAN
docs.
More information about the ckan-discuss
mailing list