Skip to main content

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

import-translations <excel_file_path> <language_sheet_name> <ts_file_path>
  • <excel_file_path>: Path to the Excel file containing the translations.
  • <language_sheet_name>: Name of the sheet in the Excel file that contains the translations.
  • <ts_file_path>: Path to the TypeScript file to be updated.

Example

import-translations path/to/translations.xlsx French path/to/translations-french.ts

This command will update the translations-french.ts file with the French translations from the translations.xlsx file, under the French Excel sheet name.

Command Line Usage with python

Example

python import_translations.py translations.xlsx French translations.ts

Excel File Format

The Excel file should have at least three columns:

  1. Key: The key for the translation.
  2. English Text: The original English text.
  3. 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 vvv and // TODO: ^^^ Translate above ^^^.

Example

Assuming the Excel workbook has a sheet named French with the following content:

Key English Text French
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

translations_util-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

translations_util-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file translations_util-0.1.1.tar.gz.

File metadata

  • Download URL: translations_util-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.10 Darwin/24.1.0

File hashes

Hashes for translations_util-0.1.1.tar.gz
Algorithm Hash digest
SHA256 710eab0d84a6ccd68627192c68f89db155278f6d7e22dcfd70da308e098ece65
MD5 759e000c6b7dd1ff772d89411f78726e
BLAKE2b-256 f3910b809d758b5249cd160a6fd8d1ec975490c92c0a6be19d93932f134b9154

See more details on using hashes here.

File details

Details for the file translations_util-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: translations_util-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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

Hashes for translations_util-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 25cbcc4326d49d51ea10ef6c924d0578df46db19440dd0d296236d38218fcd7b
MD5 62575f9c53b5bc5eb3f8a7d6f92309fe
BLAKE2b-256 24e45a5f8daf4fc610538ab5e7797422cc459b0eb763a2391ff288f61c4954ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page