geosolutions-it/ckan-custom-translations

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Ckan - custom translations

This project contains custom string translations for Ckan, along with tools for maintaining translation merging etc.

Updating translation strings

Strings get merged this way:

Usage
Make Ckan load custom translations

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).

How to make extensions translatable?

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
Collecting strings & starting translating

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 .pos.

Updating strings

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.

Debugging problems with messages

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.