[ckan-discuss] CKAN Customization...

Koebrick, Andrew (MNIT) andrew.koebrick at state.mn.us
Wed Oct 23 16:45:19 BST 2013


Stefan,

Thanks for the additional info.  I kludged together another solution- I hijacked another language for our custom localization .mo and .po files.  At first I overrode the Latvian translation (lt) thinking that the odds of our tool being used by anyone from Latvia was slim to none.   But it turned out that this had the unfortunate effect of also causing our Discus plugin to get translated into Latvian.  So now I have overridden the en_GB files with our localization.  Hopefully our site will not now be full of "Cheerio", "Blimey", "Motorway" and other British  colloquialisms.  :-)

Andrew



From: Stefan Oderbolz [mailto:stefan.oderbolz at liip.ch]
Sent: Wednesday, October 23, 2013 3:01 AM
To: Koebrick, Andrew (MNIT)
Cc: ckan-discuss at lists.okfn.org
Subject: Re: [ckan-discuss] CKAN Customization...

Hi Andrew,

yes this process is very unclear, especially if you try to replace the English translation. I'm not sure if there is a clean solution, but I can describe our approach.

As you can see, we maintain "our" own translation files in seperate extension, to use it you have to do two things:
1. Compile the po files to mo files
2. Copy everything to the ckan i18n directory

We use the following script where we have ckan installed at /home/www-data/pyenv/src/ckan and our extensions at /home/www-data/ckanext-ogdch:

rm -rf /home/www-data/pyenv/src/ckan/ckan/i18n/en
cp -r /home/www-data/ckanext-ogdch/ckanext/ogdch/i18n/en/ /home/www-data/pyenv/src/ckan/ckan/i18n/en
python setup.py compile_catalog --locale en
rm -rf /home/www-data/pyenv/lib/python2.7/site-packages/ckan/i18n/en/
cp -r /home/www-data/pyenv/src/ckan/ckan/i18n/en/ /home/www-data/pyenv/lib/python2.7/site-packages/ckan/i18n/en

This works just like that for all languages except English. The problem here is, that English is the base language for all translations (no matter which default you set with ckan.locale_default). I.e. there is no original translation for "en". Therefore in the i18n module of python there is a check if the language is "en" and if so, no translations are loaded, hence you have to change the module to make it load "en" translations:

diff --git a/ckan/lib/i18n.py b/ckan/lib/i18n.py
index ca6c168..affd34c 100644
--- a/ckan/lib/i18n.py
+++ b/ckan/lib/i18n.py
@@ -126,8 +126,7 @@ def handle_request(request, tmpl_context):
     ''' Set the language for the request '''
     lang = request.environ.get('CKAN_LANG') or \
         config.get('ckan.locale_default', 'en')
-    if lang != 'en':
-        set_lang(lang)
+    set_lang(lang)
     tmpl_context.language = lang
     return lang

@@ -144,5 +143,4 @@ def set_lang(language_code):
     ''' Wrapper to pylons call '''
     if language_code in non_translated_locals():
         language_code = config.get('ckan.locale_default', 'en')
-    if language_code != 'en':
-        _set_lang(language_code)
+    _set_lang(language_code)

So as you you see, it's a small change, but it's necessary to get "en" to work. Maybe there is a better solution, but I couldn't find it yet.

- Stefan



On Mon, Oct 21, 2013 at 11:31 PM, Koebrick, Andrew (MNIT) <andrew.koebrick at state.mn.us<mailto:andrew.koebrick at state.mn.us>> wrote:
Stefan,

I would like to duplicate your group-> category change via the translation files, but am a little unclear on the process.  I have downloaded your .po file, used msgfmt  to create a .mo file, but am not having any success getting it to influence the output.  I have tried a few options:

1)      I put the .po and .mo into our extension directory (ckanext-geodatamn/ckanext/geodatamn/i18n/en/LC_MESSAGES)

2)      I tried putting them in the main ckan i18n directory, under a new localization directory (to distinguish it from the standard English) (ckan/ckan/i18n/mngeo/LC_MESSAGES) and then altered the ckan .ini  ckan.locale_default value to mngeo.  No luck- the server  gives a 500 error with the message "default language "mngeo" not available"

3)      I would also try just putting our .mo file into the default en directory, but see only a en_AU and  en_GB.  It is unclear to me how these relate to the the "en" declared in the .ini file.  Is one of these called before the other?  Am I just looking in the wrong location?
Any extra info you can supply on your localization process would be appreciated.

Andrew

From: ckan-discuss-bounces at lists.okfn.org<mailto:ckan-discuss-bounces at lists.okfn.org> [mailto:ckan-discuss-bounces at lists.okfn.org] On Behalf Of Stefan Oderbolz
Sent: Wednesday, October 09, 2013 2:32 AM
To: ckan-discuss at lists.okfn.org<mailto:ckan-discuss at lists.okfn.org>
Subject: Re: [ckan-discuss] CKAN Customization...

Hi Mark,

for the Swiss Open Data portal we replaced the "group" terminology with "category" by changing the translations files.
It's some initial effort that's true, but it's not very complicated (see https://github.com/ogdch/ckanext-ogdch/blob/develop/ckanext/ogdch/i18n/en/LC_MESSAGES/ckan.po).

- Stefan



On Tue, Oct 8, 2013 at 7:59 PM, Sean Hammond <sean.hammond at okfn.org<mailto:sean.hammond at okfn.org>> wrote:
> I actually used this extension to hide groups:
> https://github.com/okfn/ckanext-hidegroups  which worked quite well.
> However you do post a good thought.  Perhaps groups are more
> applicable than organizations in my case.  Nonetheless, what is the
> best approach to changing the terminology?  Do I need to global search
> and replace, or, is there database data that needs changing as well?
You shouldn't need to change anything in the database, as far as I know.

You could write your own CKAN theme and wherever the word "organization"
appears in one of the CKAN templates (global search of the
ckan/templates/ directory) override that template or templace block and
change the word. See the new theming tutorial (in progress):

http://docs.ckan.org/en/847-new-theming-docs/theming.html

Another possible approach (not documented) would be to add an en_CA
translation (Or whatever variation of English you want) and use the
translations to change the word.

Neither of these approaches would replace the word organization in e.g.
API call parameters and return values, or in URLs.

For the URLs it could perhaps be done with a CKAN plugin implementing the
IRoutes plugin interface.

API parameter and returns could be customized from a plugin also, I
suppose.

All in all, it seems to me like a lot of effort to go to, I'd recommend
just sticking with the default terminology if possible.

> As for the addition handler, I would simply like to add one more
> option to the Explore menu - right now there is preview and download.
> I would like to add Download by Area of interest.
Simply adding another link to the explore button can be done by a CKAN
theme with a simple custom template, see the tutorial I linked to above,
it's just a case of finding the right template file and block,
overriding it, and adding your link.

But what should this link link to? What does it do?

_______________________________________________
ckan-discuss mailing list
ckan-discuss at lists.okfn.org<mailto:ckan-discuss at lists.okfn.org>
http://lists.okfn.org/mailman/listinfo/ckan-discuss
Unsubscribe: http://lists.okfn.org/mailman/options/ckan-discuss



--
Liip AG  //  Feldstrasse 133 //  CH-8004 Zurich
Tel +41 43 500 39 80<tel:%2B41%2043%20500%2039%2080> // GnuPG 0x7B588C67 // www.liip.ch<http://www.liip.ch/>



--
Liip AG  //  Feldstrasse 133 //  CH-8004 Zurich
Tel +41 43 500 39 80 // GnuPG 0x7B588C67 // www.liip.ch<http://www.liip.ch/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-discuss/attachments/20131023/c96cd160/attachment-0001.htm>


More information about the ckan-discuss mailing list