The translations service server
Manage, store and deliver translations.
A translation starts out with a key, usually the English version of the text. For each key there can be a translation for another language. That is the second parameter for a translation.
A translation can also be country depended, the third parameter.
The last parameter specifies the plural version of the translation. This is needed for when the translation refers to some amount and needs to be different depending on what that amount is.
Rules for finding a translation
The parameters for getting a translation are:
- key: the text to translate
- lang: the language for the translation, following ISO 639-1
- country [optional] the country for the translation, following ISO 3166-1 alpha-2
- plural [optional] the related value that defines the plural form of the translation
The steps taken to find a translation are:
- find all translations for the given key
- only keep the ones with the specified language
- from that list keep the ones with a matching country, if there are no entries with a matching country keep the ones without a specified country
- if a plural parameter was specified try to find entries with that plural value otherwise select the translation where no plural value was specified
- if more than one translations are left take the first one, if no translation is left take the key as the translation instead
Prepare a Postgres database and user.
Create and activate a Python 3 virtual environment.
Clone/download the project.
Then go to that project folder and run:
$ npm install $ export TRANSLATIONS_SERVER_DB_URL="<YOUR DATABASE URL>" $ grunt migrate $ cd src $ cp config_local.py.example config_local.py
Review and edit this new file
Database URL example
Connecting to a database named
test`on a local postgres server with user
`postgres and no password: “
After completing the installation and activating the Python environment go to the project folder and start a development server like this:
$ cd src $ ./main.py
How you run your server in production depends on your production environment.
./main.py --help for port options.
Prepare an empty test database and configure it in through
config_local.py. Then go to the project
folder and run:
$ cd test $ ./run_tests.py
Add and edit translations
Theres are each a table for languages and countries. If a new alnguage or country is needed those tables need to be updated first:
translations_server=# INSERT INTO languages (language_code, name) VALUES ('en', 'English'); translations_server=# INSERT INTO countries (country_code, name) VALUES ('US', 'United States of America');
There is no support for states, yet. Optionally one could modify the countrie codes to include the states information.
All translations then reside in the
translations table, which contains:
- translation_key: The key (original text) for the translation.
- language_id: References
- country_id: References
- plural: The plural count (variation) for which this translation is for.
- translation_text: The translated text.
The server takes on request at the configured port number and responds with a replay to each request.
Each request shall send at least 4 frames containing:
- country or `""`
- plural or `""`
Each request may further contain more frames in pairs, each containing:
- plural or `""`
"sv" "" "User not active" ""
An example requesting two translations:
"sv" "" "User not active" "" "User not found" ""
The server shall then respond with either exactly one frame containing an empty string or as many frames as keys where send, each containing the translation for the corresponding key.
The response with only one frame containing an empty strings signals a server error.
Response example for requesting two keys:
"Användare ej aktiv" "User not found"
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|TranslationsServer-0.1.1-py3-none-any.whl (10.9 kB) Copy SHA256 Checksum SHA256||py3||Wheel||Aug 1, 2016|
|TranslationsServer-0.1.1.tar.gz (7.9 kB) Copy SHA256 Checksum SHA256||–||Source||Aug 1, 2016|