![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
json-autotranslate
Advanced tools
Translate a folder of JSON files containing translations into multiple languages.
This tool allows you to translate a locale folder containing multiple JSON files into multiple languages using Google Translate, DeepL, Azure Translator, or manually. You can either use the translation keys (natural translation) or their values (key-based translation) as a source for translations.
If some of the strings have already been translated, they won't be translated again. This improves performance and ensures that you won't accidentally lose existing translations.
Interpolations (ICU: {name}
, i18next: {{name}}
, sprintf: %s
) are replaced
by placeholders (e.g. <0 />
) before being passed to the translation service,
so their structure doesn't get mangled by the translation.
$ yarn add json-autotranslate
# or
$ npm i -S json-autotranslate
$ yarn json-autotranslate
# or
$ npx json-autotranslate
Translate natural language source files located in the locales
directory using
Google Translate and delete existing keys in translated JSON files that are no
longer used.
$ yarn json-autotranslate -i locales -d -c service-account.json
Manually translate key-based source files located in the locales
directory.
$ yarn json-autotranslate -i locales -s manual
Your locales
directory should look like this:
locales
├── de
├── en
│ ├── login.json
│ └── register.json
├── fr
└── it
If you don't specify another source language, this tool will translate all files
located in the en
into all other languages that exist as directories. A single
language directory (e.g. en
) should only contain JSON files. Sub-directories
and other files will be ignored.
There are two ways that json-autotranslate can interpret files:
natural
)key-based
)If you don't specify a file structure type, json-autotranslate will automatically determine the type on a per-file basis. In most cases, this is sufficient.
This is the default way that this tool will interpret your source files. The
keys will be used as the basis of translations. If one or more of the values in
your source files don't match their respective key, you'll see a warning as this
could indicate an inconsistency in your translations. You can fix those
inconsistencies by passing the --fix-inconsistencies
flag.
{
"Your username doesn't exist.": "Your username doesn't exist.",
"{email} is not a valid email address.": "{email} is not a valid email address."
}
If you pass use the keybased
option (--type keybased
), this tool will use
the source file's values as the basis of translations. Keys can be nested, the
structure will be transfered over to the translated files as well.
{
"ERRORS": {
"USERNAME": "Your username doesn't exist.",
"EMAIL": "{email} is not a valid email address."
},
"LOGIN": "Login",
"FORGOT_PASSWORD": "Forgot password?"
}
As of this release, json-autotranslate offers five services:
You can select a service using the -s
or --service
option. If you specify
the --list-services
flag, json-autotranslate will output a list of all
available services.
To use this tool with Google Translate, you need to obtain valid credentials from Google. Follow these steps to get them:
You can specify the location of your downloaded JSON key file using the -c
or
--config
option.
To use this tool with DeepL, you need to obtain an API key from their website. API keys are only available to DeepL Pro API users. If you don't have a Developer account yet, you can create one here.
DeepL charges a fixed monthly price plus a variable fee for every 500 translated characters.
After you have completed your sign-up, you can pass the API key to
json-autotranslate using the -c
or --config
option.
To use this tool with Azure's Translator Text, you need to obtain an API key
from their website. Sign Up for an
Azure account if you don't have one already and
create a new translator instance.
You'll get an API key soon after that which you can pass to json-autotranslate
using the -c
or --config
flag.
As of now, the first 2M characters of translation per month are free. After that you'll have to pay $10 per 1M characters that you translate.
This service doesn't require any configuration. You will be prompted to translate the source strings manually in the console.
Matchers are used to replace interpolations with placeholders before they are sent to the translation service. This ensures that interpolations don't get scrambled in the process. As of this release, json-autotranslate offers four matchers for different styles of interpolation:
%s
)You can select a matchers using the -m
or --matcher
option. If you specify
the --list-matchers
flag, json-autotranslate will output a list of all
available matchers.
Options:
-i, --input <inputDir> the directory containing language directories (default: ".")
-l, --source-language <sourceLang> specify the source language (default: "en")
-t, --type <key-based|natural|auto> specify the file structure type (default: "auto")
-s, --service <service> selects the service to be used for translation (default: "google-translate")
--list-services outputs a list of available services
-m, --matcher <matcher> selects the matcher to be used for interpolations (default: "icu")
--list-matchers outputs a list of available matchers
-c, --config <value> supply a config parameter (e.g. path to key file) to the translation service
-f, --fix-inconsistencies automatically fixes inconsistent key-value pairs by setting the value to the key
-d, --delete-unused-strings deletes strings in translation files that don't exist in the template
-h, --help output usage information
If you'd like to contribute to this project, please feel free to open a pull request.
FAQs
Translate a folder of JSON files containing translations into multiple languages.
The npm package json-autotranslate receives a total of 1,885 weekly downloads. As such, json-autotranslate popularity was classified as popular.
We found that json-autotranslate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.