Command line tools for extracting and importing translations from and to excel files
Project description
translations-util
Command line tools for extracting and importing translations from and to Excel files.
Installation
CLI tool
Installs the package globally so that you can use the command line tool from anywhere.
pip install translations-util
Install as a Python package
Installation with Poetry
To install using Poetry:
poetry add -D translations-util
Which will install the utils as a development dependency in your local python environment.
Usage
This tool allows you to update translations in a TypeScript file based on an Excel file. The Excel file should contain the translations in a specific format.
CLI usage
Command
translation-util {import,export} ...
Import Command
translation-util import <excel_file> <ts_file> <sheet_name>
<excel_file>: Path to the Excel file containing the translations.<ts_file>: Path to the TypeScript file to be updated.<sheet_name>: Name of the sheet in the Excel file that contains the translations.
Export Command
translation-util export <ts_file> <excel_file> <sheet_name>
<ts_file>: Path to the TypeScript file containing translations.<excel_file>: Path to the Excel file to save exported translations.<sheet_name>: Sheet name to save translations under in the Excel file.
Example
translation-util import path/to/translations.xlsx path/to/translations-french.ts French
This command will update the translations-french.ts file with the French translations from the translations.xlsx
file, under the French Excel sheet name.
translation-util export path/to/translations-french.ts path/to/translations.xlsx French
This command will export the translations from the translations-french.ts file to the translations.xlsx file, under the French Excel sheet name.
The Excel will follow the format from the Excel File Format section.
Excel File Format
The Excel file should have at least three columns:
- Key: The key for the translation.
- English Text: The original English text.
- Translation: The translated text.
Features
- Placeholder Matching: Ensures that placeholders in the format
{variable}are consistent between the English text and the translation. - Translation Blocks: Detects and processes translation blocks marked by
// TODO: vvv Translate below vvvand// TODO: ^^^ Translate above ^^^.
Example
Assuming the Excel workbook has a sheet named French with the following content:
| Key | English Text | French text |
|---|---|---|
| common.greeting-{name} | Hello, {name}! | Bonjour, {name}! |
| common.goodbye | Goodbye! | Au revoir! |
| login.username | Username | Nom d'utilisateur |
| login.password | Password | |
| error.invalid-translation-of-variable-{name} | Invalid translation of variable {name} | Traduction invalide de variable {nom} |
The import-translations command will update the TypeScript file with the following content:
export const translations = {
..., // Other translations
'common.existing-translation': 'Traduction existante',
'common.greeting-{name}': 'Bonjour, {name}!',
'common.goodbye': 'Au revoir!',
'login.username': "Nom d'utilisateur",
'login.password': '', // TODO Translate
'error.invalid-translation-of-variable-{name}': '', // TODO Translate
... // Other translations
};
Development
To contribute to this project, clone the repository and install the dependencies using Poetry:
git clone <repository-url>
cd translations-util
poetry install
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file translations_util-0.2.2.tar.gz.
File metadata
- Download URL: translations_util-0.2.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.10 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa8d3444d3151f2fc1d35d8c6822f71d49511e1e1ba960eca78648fd5f0a649
|
|
| MD5 |
20182561e8d8f6cffb568fa1bf773d26
|
|
| BLAKE2b-256 |
0f2f763fd4bf7871a59d7b5e908ad4f1f3efb83d46978ff16c9e3ae2c5525b2e
|
File details
Details for the file translations_util-0.2.2-py3-none-any.whl.
File metadata
- Download URL: translations_util-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.10 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be9823a4ff86a192879f0a998d1abcddee93936aefb970f2cf3e531d297bf351
|
|
| MD5 |
0c2201b0034942bff0b9040bae08d452
|
|
| BLAKE2b-256 |
7dfa968dab66c908e4564313cd217201c24c8ef19b64e1f6bef28d37fa470401
|