Package: json-translate
json-translateCLI tool to translate JSON files automatically using external translation services likeDeepLorAWS TranslateNormally, multilingual projects base their translations on JSON files with different levels of nesting. This small project makes it easy to generate new files for new languages while keeping the same structure.json_translatedeepl/path/to/input-file.jsonFR# Input file:                    Output file:# {                              {#   "welcome": "Welcome!",         "welcome": "Bienvenue!",#   "questions": {                 "questions": {#     "sure": "Are you sure?"        "sure": "Êtes-vous sûr?"#    }                             }# }                              }The supported languages depends on the service used:DeepL supported languages.AWS supported languages.InstallInstall dependencies:pipinstalljson-translateTo define the environmental variables, create an.envfile in the root directory with the required variables, which will vary depending on the external service you will use:EXAMPLE_VARIABLE_NAME=example_variable_valueYou can also define them directly in your environment without having to create the.envfile, it's up to you.Use with DeepLYou can use DeepL with a free account or with a paid account.Free account: You can get a free deepl developer account inhttps://www.deepl.com/pro-checkout/account(Credit card needed). Once you have registered, you must include your auth key in the.envfile:DEEPL_AUTH_KEY=your-key-herePaid account: If you have a paid account, in addition to including your auth key, you must include the API endpoint in the file.DEEPL_AUTH_KEY=your-key-here
DEEPL_API_ENDPOINT=https://api.deepl.com/v2/translateUse with AWS TranslateLogin on your AWS account and obtain your credentials and place them in the.envfile:AWS_REGION_NAME=your-aws-region
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secretHow to useExecute the command with the service, the file path and the language you want to generate:json_translate<service><source><locale># Example: json_translate aws locales/en.json ESThe script will create anes.jsonfile in the same folder as the source file.Required parametersservice               Translation service to use. Can be "deepl" or "aws"
source                Path to source file (must be a json file)
target_locale         Translation target language codeOptional parameters-sl, --source-locale  Source language translating from (Required for AWS).
-o, --output          Output file name. Defaults to "<target_locale>.json" (ex: en.json)
-e, --extend          Extend the existing translation file (defined by <output>)
-s, --sleep           Sleep time between API calls. Defaults to 0.01 (seconds)
-i, --indent          Output file indentation spaces. Defaults to 2
--encoding            Input & output file encoding. Defaults to UTF-8
--skip                Keys to skip in the json file (they won't be translated)
--log                 Display translations as they are being translated
--override            Force override on output fileDeepL options-g, --glossary        Glossary ID to use when translating (Optional)AWS Translate options--formality           Set formality level to FORMAL
--profanity           Mask profane words and phrasesNote thatsleep,indentationandencodingcan also be defined with variables in the.envfile but they are overwritten with the values of the command:SLEEP_BETWEEN_API_CALLS=0.01
INDENTATION_DEFAULT=2
ENCODING=utf-8Example fileTranslate the example file/tests/data/en_US.jsonto spanish:json_translatedeepltests/data/en_US.jsonES--skiploremipsum--logDeepL API usageYou can check your API usage withcurl-H"Authorization: DeepL-Auth-Key YOUR-API-KEY-HERE"https://api-free.deepl.com/v2/usageContributingSee thecontributing guidefor detailed instructions on how to get started.LicenseThis repository is available underGNU LESSER GENERAL PUBLIC LICENSE v2.1(LGPL).