i18ntools helps translate Java properties i18n files using Azure Cognitive Services Translator
Project description
i18ntools
Translate i18n Java properties files to desired language(s).
Description • Installation • Usage • License
Description
i18ntools is a collection of Python scripts to help translate your Java properties internationalization files using Azure Cognitive Services Translator.
What does each script do?
- translate.py translates an entire i18n Java properties file into a new i18n Java properties file of a different language.
- translate_missing.py translates the messages in an i18n Java properties file that are missing
from an i18n Java properties file of a different language.
The missing messages will be appended at the end of the output file unless the
--sort
option is used. Note: using the--sort
option will delete comments in the output file that are not present in the input file. - parse_i18n_file.py reads an i18n Java properties file and returns the data as a dictionary.
- sort_i18n_file.py sorts the messages in a given i18n Java properties file so that they are in the same order as the messages in a different i18n Java properties file. Using this script will delete comments in the sorted output file that are not present in the input file.
Installation
You can currently only clone this repository to run the scripts:
git clone git@github.com:hypercision/i18ntools.git
Navigate to the cloned repository and create a virtual environment to run these Python scripts on your local machine:
cd i18ntools
python -m venv i18n_env
source i18n_env/bin/activate
The command to activate the virtual environment on Windows is:
i18n_env\Scripts\activate.bat
Then install the packages required by our scripts and an editable installation of this package:
pip install -r requirements.txt
pip install --editable .
When this package is installed, CLI executables of the scripts will be installed on the path of your virtual environment.
translate --help
translate-missing --help
parse-i18n-file --help
sort-i18n-file --help
Python “Virtual Environments” allow Python packages to be installed in an isolated location
for a particular application, rather than being installed globally.
You should run all your Python commands with your virtual environment activated.
Once you are done using Python, you can exit the virtual environment by entering deactivate
in your terminal.
Usage
Before using translate.py
or translate_missing.py
, your Azure API secret key must be set in
an environment variable named TRANSLATOR_API_SUBSCRIPTION_KEY
.
export TRANSLATOR_API_SUBSCRIPTION_KEY=<your_key>
You can accomplish this on Windows with the following command:
C:\>set TRANSLATOR_API_SUBSCRIPTION_KEY=<your_key>
Suppose you have the following in a file named /home/docs/example.properties
:
default.invalid.min.message=Property [{0}] of class [{1}] with value [{2}] is less than minimum value [{3}]
# Track 4 on Expert In A Dying Field
TheBeths.YourSide.lyrics=I want to see you knocking at the door. \
I wanna leave you out there waiting in the downpour. \
Singing that you’re sorry, dripping on the hall floor.
instructor.submitWithCustomTime.customSubmitTS.missing.error=The customSubmitTS parameter is missing. \
It must be present and of type Date.
# SessionItem.itemID is the first parameter
instructorService.removeSession.success={0} session removed.
handshake.register.suspended.error=The trial period has ended for your account \
and you can no longer use the application.
handshake.register.disabledException.error=Instructor is disabled
When you run:
translate -i=/home/docs/example.properties -t=es
# Or you could call the file directly
python src/i18ntools/translate.py -i=/home/docs/example.properties -t=es
Then a new file named /home/docs/example_es.properties
will be saved and contain Spanish translations
of the input file, with the comments preserved:
default.invalid.min.message=La propiedad [{0}] de la clase [{1}] con valor [{2}] es menor que el valor mínimo [{3}]
# Track 4 on Expert In A Dying Field
TheBeths.YourSide.lyrics=Quiero verte llamando a la puerta. \
Quiero dejarte ahí afuera esperando bajo el aguacero. \
Cantando que lo sientes, goteando en el piso del pasillo.
instructor.submitWithCustomTime.customSubmitTS.missing.error=Falta el parámetro customSubmitTS. \
Debe estar presente y ser de tipo Fecha.
# SessionItem.itemID is the first parameter
instructorService.removeSession.success={0} sesión eliminada.
handshake.register.suspended.error=El período de prueba ha finalizado para su cuenta \
y ya no puede usar la aplicación.
handshake.register.disabledException.error=El instructor está deshabilitado
Options
These are the options for translate.py
.
Details about how to use each file can be found by running it with the --help
flag:
python src/i18ntools/translate_missing.py --help
.
Key | Alias | Description | Default |
---|---|---|---|
--help | -h | All available options. | / |
--region | -r | Region of the Azure translator resource. | eastus2 |
--input_file [required] | -i | Path to a .properties file to translate. |
/ |
--from_lang | -f | From which language you want to translate. | en |
--to [required] | -t | To which language you want to translate. For example, use de to translate to German. | / |
--output_file | -o | Path where the translated .properties file will be saved. Overwrites any existing file. |
input_file with the output language appended to the filename; i.e., messages.properties would become messages_de.properties . |
Obtaining API keys
- Azure
- Follow the instructions here.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file i18ntools-0.1.0.tar.gz
.
File metadata
- Download URL: i18ntools-0.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4374292a01c99795cd02b4dcd6cf852f85e2801914fa72f074e5610dcc2ec3d8 |
|
MD5 | d15f861984d4c31425d4a7f2d060fda7 |
|
BLAKE2b-256 | 1b31fb00de9db2d0a2d6c4999b2b63b14f6ac30ba05a87af489947ebf6919980 |
File details
Details for the file i18ntools-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: i18ntools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d558217ce49e7285340cb7a82295cf933712eaed22bfe48fbb7af93df2b61aad |
|
MD5 | 315f4af5cac955620cee17850bcdafe1 |
|
BLAKE2b-256 | 9225fa941bf03c134083a150a70506c7e4eb4fb1e8dfc56cf73f1c97c8d75ef5 |