|
| 1 | +# Translating LORIS |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Helping with translating LORIS into a language that you speak is |
| 6 | +an easy way to help LORIS without touching any code. |
| 7 | + |
| 8 | +If you're using a language that is already translated and a translation |
| 9 | +appears wrong, the first thing you can do is [open a bug report.](https://github.com/aces/Loris/issues/new?template=bug_report.md). Try and include |
| 10 | +the page, incorrect words, and correct phrasing (and/or dialect if applicable) |
| 11 | +in your bug report. |
| 12 | + |
| 13 | +Otherwise, you most likely want to help with one of two tasks: |
| 14 | +- Adding a new language to LORIS |
| 15 | +- Adding translations for an existing language to a module in LORIS. |
| 16 | + |
| 17 | +The steps for each are similar. |
| 18 | + |
| 19 | +## Architecture |
| 20 | + |
| 21 | +Translatable strings used by LORIS are stored in `.po` (portable object) |
| 22 | +files which is the standard used by `gettext` library. These are compiled |
| 23 | +into both the `json` files used by the javascript frontend, and the `mo` files |
| 24 | +used by the PHP backend, so that the same translations are used throughout |
| 25 | +LORIS. |
| 26 | + |
| 27 | +(For advanced usage of the format in languages that include multiple forms of |
| 28 | +plural an internet search is likely to provide better guidance than this |
| 29 | +documentation, which is aimed at contributing to LORIS.) |
| 30 | + |
| 31 | +Each translatable module in LORIS has a `locale` subdirectory for strings that |
| 32 | +are specific to that module (ie. `modules/candidate_list/locale` for the |
| 33 | +`candidate_list`) while LORIS has a `locale` directory on the top level |
| 34 | +for terms that are used throughout LORIS. |
| 35 | + |
| 36 | +Within the locale directories, there is a `.pot` (".po template") file with |
| 37 | +the same name as the module (or "loris.pot" for the core terms). The `.pot` |
| 38 | +is a template with translateable strings for a new language. |
| 39 | + |
| 40 | +Both `po` and `pot` files have similar structures and can be either be edited |
| 41 | +by hand or with any translation software which supports the format. |
| 42 | + |
| 43 | +Inside the locale directory, there is a subdirectory for each supported language. |
| 44 | +The language directory has an `LC_MESSAGES` subdirectory which has the `.po` file |
| 45 | +with the translated strings for that language. (This directory structure is imposed |
| 46 | +by gettext and not specific to LORIS.) |
| 47 | + |
| 48 | +The primary difference between adding a new language or adding translations for |
| 49 | +an existing language is whether the language subdirectory already exists. |
| 50 | + |
| 51 | +## Example |
| 52 | + |
| 53 | +Suppose you wanted to translate LORIS to a fictional language which is exactly |
| 54 | +the same as English but every word starts with "L". This fictional language has |
| 55 | +the language code of "lo". |
| 56 | + |
| 57 | +The first thing step is to create the `locale/lo/LC_MESSAGES` directory and |
| 58 | +copy the `locale/loris.pot` template to `locale/lo/LC_MESSAGES/loris.po`. |
| 59 | + |
| 60 | +Within the file, near the top of the there is a block of metadata for the file |
| 61 | +which looks something like: |
| 62 | + |
| 63 | +``` |
| 64 | +"Project-Id-Version: LORIS 27\n" |
| 65 | +"Report-Msgid-Bugs-To: https://github.com/aces/Loris/issues\n" |
| 66 | +"POT-Creation-Date: 2025-04-08 14:37-0400\n" |
| 67 | +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 68 | +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 69 | +"Language-Team: LANGUAGE <[email protected]>\n" |
| 70 | +"Language: \n" |
| 71 | +"MIME-Version: 1.0\n" |
| 72 | +"Content-Type: text/plain; charset=UTF-8\n" |
| 73 | +"Content-Transfer-Encoding: 8bit\n" |
| 74 | +``` |
| 75 | + |
| 76 | +You can edit it as appropriate, but the most important part (from a technical |
| 77 | +perspective) is that the "Language" line needs to be updated to match your |
| 78 | +language's language code, in this example it would be changed to read: |
| 79 | + |
| 80 | +``` |
| 81 | +"Language: lo\n" |
| 82 | +``` |
| 83 | + |
| 84 | +(This step may already be done if you're updating an existing language.) |
| 85 | + |
| 86 | +Next, comes inserting the translations themselves. |
| 87 | + |
| 88 | +The template you copied you copied should have a series of msgid/msgstr lines such |
| 89 | +as the following: |
| 90 | + |
| 91 | +``` |
| 92 | +msgid "LORIS" |
| 93 | +msgstr "" |
| 94 | +
|
| 95 | +msgid "DEV" |
| 96 | +msgstr "" |
| 97 | +
|
| 98 | +msgid "Affiliations" |
| 99 | +msgstr "" |
| 100 | +``` |
| 101 | + |
| 102 | +msgid is generally the English string, and msgstr should be updated with the |
| 103 | +translation. In our fictional language, this would become: |
| 104 | + |
| 105 | +``` |
| 106 | +msgid "LORIS" |
| 107 | +msgstr "LORIS" |
| 108 | +
|
| 109 | +msgid "DEV" |
| 110 | +msgstr "LDEV" |
| 111 | +
|
| 112 | +msgid "Affiliations" |
| 113 | +msgstr "Laffiliations" |
| 114 | +``` |
| 115 | + |
| 116 | +Congratulations, you've translated LORIS into the fictional `lo` language! |
| 117 | + |
| 118 | +You can repeat this process for any module within the module's `locale` |
| 119 | +directory. |
| 120 | + |
| 121 | +## Send Pull Request |
| 122 | + |
| 123 | +The last step is to send a pull request to LORIS so that your translation |
| 124 | +can be included in the next release. Due to the size of LORIS, it's best to translate one module at a time and send one pull request per module. |
| 125 | + |
| 126 | +If you're not familiar with git or GitHub you can review [GitHub's](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) provides documentation on how |
| 127 | +to send a pull request. |
| 128 | + |
| 129 | +If you still not sure how to send a pull request, including the `po` file |
| 130 | +that you've created in a GitHub issue, a developer may be able to help you |
| 131 | +or create it for you. |
0 commit comments