Translating depositar

String internationalization

Our customized extension can be internationalized. This guide shows how to internationalize strings.

Note

This is the simplified version. For details please refer to String internationalization in CKAN’s documentation.

  1. Internationalizing strings in Jinja2 templates

    To internationalize a string put it inside a _() function:

    {% set hello = _('Hello World!') %}
    
  2. Internationalizing strings in Python code

    To internationalize a string put it inside a _() function:

    my_string = _("This paragraph is translatable.")
    
  3. Internationalizing strings in JavaScript code

    To internationalize a string put it inside a this._() function:

    this._('Something that should be translated')
    

Extract strings and edit translations

Before editing translations, you should extract strings from the customized extension.

Important

The virtualenv has to remain active for the rest of the installation and deployment process, or commands will fail. You can tell when the virtualenv is active because its name appears in front of your shell prompt, something like this:

(default) $ _

For example, if you logout and login again, or if you close your terminal window and open it again, your virtualenv will no longer be activated. You can always reactivate the virtualenv with this command:

. /usr/lib/ckan/default/bin/activate

Important

Please run all the commands below under the directory where the customized extension is installed.

cd /usr/lib/ckan/default/src/ckanext-data-depositario
  1. Extract strings to be translated:

    python setup.py extract_messages
    
  2. Create translation files for a locale:

    Note

    We will create translation files for the zh_TW locale.

    Since the zh_TW locale already exists, we run the update_catalog command to keep the translated strings. If you want to create a new locale, please use init_catalog instead.

    python setup.py update_catalog -l zh_TW
    
  3. Open the generated translation file and add translations for it by editing the msgstr section:

    vi ckanext/data_depositario/i18n/zh_TW/LC_MESSAGES/ckanext-data_depositario.po
    
  4. Compiling the catalog:

    python setup.py compile_catalog
    
  5. Restart CKAN:

    Note

    In this tutorial we are assuming that you have finished Deploying a source install.

    sudo stop ckan && sudo start ckan