Skip to content

Translating Watcher

nosmokingbandit edited this page Aug 13, 2017 · 1 revision

Watcher's web interface has the ability to be translated into any language. If you would like to help translate Watcher follow the guide below.

Overview

Two files are responsible for containing translated strings, watcher.po and localization.js. Messages from the backend require watcher.po and messages constructed in the browser require localization.js. Neither file must be complete for Watcher to use it for translation, but any missing strings will be displayed in English.

Preparation

Language Code

First you must determine the ISO 639-1 code for your chosen language. A complete list of codes may be found at (https://www.loc.gov/standards/iso639-2/php/code_list.php)[www.loc.gov]. All languages in Watcher are referred to by their two-letter, lower-case code. For example, Russian is ru, German is de, etc.

watcher.po

Navigate to watcher/locale and make a copy of watcher.po. Create a new directory in the locale directory using the two-letter language code described above. Inside this directory create another directory named LC_MESSAGES. Place your copy of watcher.po in this directory.

localization.js

Every language is contained in localization.js, so we will not be making a copy. Open a terminal and navigate to watcher/static/js. This directory contains a script get_strings.py that we will use to collect a list of strings in javascript files to be translated. Execute the script as python3 get_strings.py -n en, using your language code in place of en. This will generate a new javascript file named js_strings_en.js.

Translating

watcher.po

There exists several applications for translating po files, this guide will use an online editor called Loco, found (here)[https://localise.biz/free/poeditor]. Upload your copy of watcher.po. Enter translated strings in the Target translation field. Several strings may contain special sequences of curly braces {}. These must be preserved as Watcher will replace them with movie titles, dates, or other information.

When you are done translating, click Save and download the .mo file. Rename this to watcher.mo and place in in the same directory as your watcher.po copy. You may also download messages-zxx.po and replace watcher.po with it. mo files are read by Watcher, whereas po files are human-readable.

localization.js

Open the js_strings_en.js file we created earlier in a text editor. This contains an object of English strings followed by empty double-quotes "". Enter the translated string in the empty quotes.

When you are done translating, copy the entire contents of your translation file into localization.js. Paste this inside the languages object, separated from other languages with a comma.

A correctly formatted localization.js looks like this:

languages = {
    "ru": {"english string: "russian string"},
    "de": {"english string: "german string"},
    "fr": {"english string: "french string"}
}

Wrapping Up

Watcher must be restarted to find new language files. In /settings/server, under Interface, you will be able to apply your translation. After refreshing the page, translated strings will be displayed.