Name: ckan-custom-translations
Owner: GeoSolutions
Description: null
Forked from: opendatatrentino/ckan-custom-translations
Created: 2016-11-17 13:58:54.0
Updated: 2016-11-17 13:58:55.0
Pushed: 2016-11-17 14:02:37.0
Homepage: null
Size: 1215
Language: Makefile
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This project contains custom string translations for Ckan, along with tools for maintaining translation merging etc.
Strings get merged this way:
Aggregate all .pot
s from a bunch of projects
Aggreagate all .po
s from a bunch of projects, separated
by language
Generate custom .po
file for each language,
by merging all the translations into the new template
(including translations from the custom file itself)
Create a directory and checkout ckan + the plugins you need inside the directory.
Important the Makefile expects to find a directory
named ckan/ckan/i18n
in the sources directory, plus
directories named ckanext-<name>/ckanext/<name>/i18n
for
each plugin. Make sure you have them
Prepare .po
files for each extra language you want to add:
h i18n/<lang-code>/LC_MESSAGES/ckan.po
(this is required as the file is included in the custom translations too..)
Call make:
SOURCESDIR=/path/to/sources LANGUAGES="en_GB it es de fr" PLUGINS="one two three"
Translate strings:
TOR i18n/<lang-code>/LC_MESSAGES/ckan.po
Then, rebuild the .mo
files:
build_mo LANGUAGES="en_GB it es de fr"
This can be done by setting the ckan.i18n_directory
configuration
option (in the [app:main]
section of ckan configuration file)
to point to the root directory of this repository (or any directory
containing a copy of the i18n
folder, for what matters).
First, create a babel configuration file, in the root of your extension folder:
ja2: **/templates/**.html]
ding = utf-8
nsions =
nja2.ext.do,
nja2.ext.i18n,
nja2.ext.with_,
an.lib.jinja_extensions.CkanExtend,
an.lib.jinja_extensions.CkanInternationalizationExtension,
an.lib.jinja_extensions.LinkForExtension,
an.lib.jinja_extensions.ResourceExtension,
an.lib.jinja_extensions.SnippetExtension,
an.lib.jinja_extensions.UrlForExtension,
an.lib.jinja_extensions.UrlForStaticExtension
Then, add jinja extractor (or, would have you guessed that, ckan extractor..)
as entry point in your setup.py
.
y_points = {
'babel.extractors': [
'ckan = ckan.lib.extract:extract_ckan',
],
p(
...
entry_points=entry_points,
Finally, create a setup.cfg
file to tell the setuptools' babel extension commands
where to search for stuff and where to put other stuff.
ract_messages]
ords = translate isPlural
comments = TRANSLATORS:
ut_file = ckanext/myplugin/i18n/ckanext-myplugin.pot
h = 80
ing_file = babel.cfg
t_catalog]
in = ckanext-myplugin
t_file = ckanext/myplugin/i18n/ckanext-myplugin.pot
ut_dir = ckanext/myplugin/i18n
ate_catalog]
in = ckanext-myplugin
t_file = ckanext/myplugin/i18n/ckanext-myplugin.pot
ut_dir = ckanext/myplugin/i18n
ious = true
pile_catalog]
in = ckanext-myplugin
ctory = ckanext/myplugin/i18n
istics = true
Ok, now that everything is in place, try to see if everything works as expected:
on setup.py extract_messages
will extract all the strings in ckanext/myplugin/i18n/ckanext-myplugin.pot
on setup.py init_catalog -l it
will create a .po
file for the Italian language, in
ckanext/myplugin/i18n/it/LC_MESSAGES/ckanext-myplugin.po
Then, you can start translating strings.
Once you're done, just run:
on setup.py compile_messages
in order to (re)build .mo
files from the .po
s.
In case you edit strings in your templates, just use this to keep up-to-date:
on setup.py extract_messages
on setup.py update_messages
then translate, and, of course, run compile_messages
again.
It seems that babel simply ignores errors encountered while scanning for messages. This tends to hide some issues that lead to missing strings.
To figure out the issues, I used this:
nsions = [
"jinja2.ext.do",
"jinja2.ext.i18n",
"jinja2.ext.with_",
"ckan.lib.jinja_extensions.CkanExtend",
"ckan.lib.jinja_extensions.CkanInternationalizationExtension",
"ckan.lib.jinja_extensions.LinkForExtension",
"ckan.lib.jinja_extensions.ResourceExtension",
"ckan.lib.jinja_extensions.SnippetExtension",
"ckan.lib.jinja_extensions.UrlForExtension",
"ckan.lib.jinja_extensions.UrlForStaticExtensio"n
= Environment(extensions=extensions)
open('/path/to/templates/blah/index.html', 'r') as f:
template = f.read()
ngs = env.extract_translations(template)
You can inspect strings
to see if all the expected strings are there,
and in case the extractor has troubles, an exception will be raised,
allowing you to see what went wrong.