Skip to content

Translations directly through the app.po files

Brian Riley edited this page Sep 26, 2018 · 16 revisions

Overview

You can update or provide a new language translation by forking this repository, updating/adding the appropriate files and then submitting your work to us via a GitHub Pull Request.

Step 1: Fork this repository

You must have a Github account to share your translations with us. To create an account please visit the Sign up page.

Once you have signed up/logged in you can return to the DMPRoadmap repository home page and create a Fork.

Step 2: Pull the repository down to your machine

If you would like to add a new language translation or update existing translations, you will need to pull down the code from your fork to your local machine. Make sure that you have 'git' installed.

For OSX and Linux users, open a terminal session and run the following commands: Where [lanuage_code] refers to the language you will be working with. If you have previously provided translations and want to simply update them this time you should run the following command

If this is your first time pulling down the DMPRoadmap code:

> git clone https://github.com/[your fork]/roadmap.git
> cd roadmap/
> git checkout [language_code]

If you already have the roadmap code on your machine, run the following from the roadmap/ directory to pull down the latest updates. Sync your fork of the repository with the original DMPRoadmap repository and then run the following commands:

> git checkout master
> git branch -D [language_code]   <-- Only run this if you've provided translations in the past
> git checkout -b [language_code]

Step 3: Update/Add the translations for your language

All of the language translations are located in config/locale/ and config/locales/. If you see a directory for your language then you may simply open the app.po file located in that directory. If your language is not present then you will need to add it. You can do that through the following commands:

> mkdir config/locale/[language_code]
> cp config/locale/app.pot config/locale/[language_code]/app.po

Basic structure of a PO file

The PO file contains some comments at the top that identify when the file was updated, who updated it, and what language it contains. Please be sure to update these when creating or updating the file.

The PO file contains an entry for each translatable text entry in the code. Each entry consists of a key 'msgid' and a translation 'msgstr'. You should NO change the 'msgid' values. The system uses these values to locate your translation when displaying a page.

Each time we release a new version of the codebase we will run a script that updates all of the language 'app.po' files. When this happens it does one of 4 things.

  1. No change: If the 'msgid' has not changed it will continue to use your translation
  2. New entry: If there is a new 'msgid' it will appear in the file with #, fuzzy above it and an empty 'msgstr'.
  3. Entry was removed: If a 'msgid' was removed it will appear in the file with a # prefix (e.g. #msgid and #msgstr.
  4. An entry was changed: If the 'msgid' was changed you will see the #msgid and #msgstr markup that contains your original translation. The new version of the 'msgid' will appear with the #, fuzzy markup above it and an empty 'msgstr'.

For example:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the app package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: app 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2018-06-06 11:32:33-0700\n"           <-- Be sure to update the revision date
"Last-Translator: john.doe@example.org\n"                <-- Provide us with your name/email 
"Language-Team: Scottish Gaelic <LL@li.org>\n"           <-- Provide the name of the language here
"Language: gd\n"                                         <-- Also note the language here
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

msgid " (DCC-UK) and "                                   <-- GetText uses 'msgid' as a key. DO NOT change it!
msgstr "(DCC-UK) agus"                                   <-- Your translations go in 'msgstr'

msgid " (e.g. School/ Department) "
msgstr " (me Sgoil / Roinn) "

#, fuzzy                                                 <-- Indicates a new entry
msgid " Customised By: "
msgstr ""

#msgid " Plan"                                           <-- '#' before the msgid/msgstr indicates an obsolete entry
#msgstr " Plana"

Updating a new entry

To update a new entry you will need to remove the 'fuzzy' comment. Then add you translation to the 'msgstr' portion.

#, fuzzy                                                 <-- Remove this line
msgid " Customised By: "
msgstr ""                                                <-- Add your translation here

Removing an obsolete entry

While not entirely necessary, it is good practice to clean out any obsolete entries from your file. To do so, simply delete both the '#msgid' and '#msgstr' lines

#msgid " Plan"                                           <-- Remove this line
#msgstr " Plana"                                         <-- Remove this line

Updating a changed entry

When an entry changes, the old version is marked as obsolete and the new entry is marked with the #, fuzzy comment. You should copy your old version of the translation over and adjust it as necessary.

#msgid "Your plan could not be updated."                 <-- Remove this line
#msgstr "Cha b 'urrainn do phlana agad ùrachadh."        <-- Copy this entry to the new 'msgstr' below and then remove this line

#, fuzzy
msgid "Your plan could not be saved without a title."    
msgstr "Cha b 'urrainn do phlana agad a bhith air a shàbhaladh gun tiotal."  <-- Update the copied entry

Notes on translating:

Line separation

Each 'msgid' and 'msgstr' combination should be separated by exactly one blank line (with no spaces in it). For example:

msgid "First entry"
msgstr "A 'chiad inntrigeadh"

msgid "Second entry"
msgstr "An dàrna inntrigeadh"

msgid "Third entry"
msgstr "An treas inntrigeadh"

Whitespace:

If a 'msgid' starts or ends with whitespace, you should retain this in your translation. The text is likely combined with another portion of text within the application's code. For example:

#msgid "Plan "
#msgstr "Plana "
``
'Plan ' in the example above may precede the name of the plan in the code and be represented as `Plan "My test plan"`. If you do not retain the whitespace the user would see `Plana"My test plan"`

#### Placeholders:
* Do not translate any values contained in the `%{}` placeholders. They are associated with variables defined elsewhere in the system. For example `You are now a member of %{organization_name} organization` is replaced with the name of the user's organization at run time: `You are now a member of University of Somewhere organization`. 

**HTML markup**
* Do not remove any HTML you may see in the translatable text. For example, do not remove the HTML list tags `<ol>` and `<li>` found in `Steps to login:<ol><li>Click on the 'Sign in' link</li><li>Select the appropriate option</li></ol>`
* Do not add your own HTML markup to translatable text unless the existing translation already contains HTML markup. Text containing HTML markup is handled differently by the application, so the code needs to be changed to allow for HTML markup if it is not already setup to do so.

### Step 4: Update the core Rails and Gem localization files
You will also need to add/edit your language's core Rails YAML localization file as well as the corresponding Bootstrap, Contact_Us and Devise YAML files. 

If your language does not exist, make a copy of the `en_GB` version and rename it with your language's code. For example: 
```shell
cp config/locales/en_GB.yml config/locales/gd.yml
cp config/locales/bootstrap/en_GB.bootstrap.yml config/locales/bootstrap/gd.bootstrap.yml
cp config/locales/contact_us/contact_us.en_GB.yml config/locales/contact_us/contact_us.gd.yml
cp config/locales/devise/devise.en_GB.yml config/locales/devise/devise.gd.yml

Note that you do not need to provide translations for the Devise invitable files.

Be sure to update the first line in each of those files from en_GB: to your language code!

Step 5: Add a database entry for your new language

If you are adding a new translation, please update the db/seeds.rb file so that it includes your new language and will make it available for new installations of the system.

languages = [
  {abbreviation: 'gd',
   description: 'Scottish Gaelic (Gàidhlig)',
   name: 'Gàidhlig',
   default_language: false}
]

Step 6: Commit your changes and push them back up to your fork on Github

> git commit -a -m "Description of your changes (e.g. Added new Scottish Gaelic (gd) translations)"
> git push origin [language_code]

Step 7: Send us your translations

Once you have finished your changes, follow the instructions on our Contributions page to submit a PR for the team to review.

Please include the rake task command that should be run by existing installations to enable your new language (e.g. rake get text:add_language_to_db[gd,Gàidhlig,0]) in your PR comments.

If any issues are found during the review process, we will contact you via GitHub's PR commenting feature and request any changes.

Once your code has been accepted it will become a part of the next release.

Clone this wiki locally