Code Monkey home page Code Monkey logo

auto-translate-json's Introduction

Auto Translate JSON

Adds a menu item to JSON files to automatically translate them into other languages using Google Translate, Aws Translate, Azure Translate, DeepL or OpenAI.

How it works

demo

When localizing an application, if you have a folder called something like translations, languages, or i18n that contains JSON files for each language, you can use this extension to right click on your primary language file and automatically create additional translations. It uses the Google/AWS/Azure Translate API to perform the translations, and you must have your own API key to make the calls.

Just create empty files with the locale names as filenames and this extension will generate their translations. For example, if you want French, create a file fr.json. Right click on en.json, pick "Auto Translate JSON" and voilà, you have a version in French.

Features

  • Option to keep existing translations, to cut down on data processing when adding new terms
  • Option to keep extra translations, if one language has additional unique terms
  • Supports nested JSON elements
  • Supports named arguments such as: "Zip code {zip} is in {city}, {state}."
  • processes all files simultaneously

Supported languages

Requirements

Since translation services are not free, you must provide your own API key.

For Google API key you need to provide just API key. Luckily Google gives a decent amount of translations in a trial period. Go here to set up your account and request a key: https://console.developers.google.com/apis/library/translate.googleapis.com

For AWS you need to provide your access key and secret key. Go here to set up your account and request an access key and secret key and region to use: https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/

For Azure you need to provide your subscription key and region. Go here to set up your account and request a subscription key: https://azure.microsoft.com/en-us/free/

For DeepL you need to provide your authentication API key. Go here to set up your account and request an API key:https://www.deepl.com/pro-api?cta=header-pro-api/

For OpenAI you need to provide just API key.Go here to set up your account and request a key: API key:https://platform.openai.com/

Getting Started

  1. Request a Google/AWS/Azure/DeepL/OpenAI Translate API key

  2. Install this extension

  3. Go to VSCode Settings>Extensions>Auto Translate JSON

    settings

  4. Enter your Google/AWS/Azure API key / access key / subscription key / region

  5. (optional) Change the Source Locale setting if you don't want English

  6. Create empty files for each locale you want to translate into. Locale should correspond to the language code used by the translation service. For example, if you want French, create a file fr.json.If you use Azure and want to translate into Serbian , create a file sr-Cyrl.json for Serbian Cyrillic translation or sr-Latn.json for Serbian Latin translation.If you use AWS or Google and want to translate into Serbian , create a file sr.json for Serbian translation.

    files

  7. Right click the source .json file (en.json by default) and pick "Auto Translate JSON"

  8. At the prompt decide if you want to preserve previously translated values (i.e. not reprocess)

    preserve-existing

  9. At the prompt decide if you want to keep extra translations

    keep-existing

  10. Verify your language files have been updated

Extension Settings

This extension contributes the following settings (Menu>Preferences>Settings):

  • auto-translate-json.sourceLocale: A failsafe to prevent processing the wrong file. Defaults to "en" for english. You can change this to any valid two letter locale code you wish to use.

  • auto-translate-json.mode: "file": files in same folder like "en.json"...; "folder": files in subfolders like "en/translation.json\

Google

  • auto-translate-json.googleApiKey: Enter your Google API key in this setting.

AWS

  • auto-translate-json.awsAccessKeyId: Enter your AWS API access key Id in this setting.

  • auto-translate-json.awsSecretAccessKey: Enter your AWS API secret access key in this setting.

  • auto-translate-json.awsRegion: Enter your AWS region in this setting.

Azure

  • auto-translate-json.azureSecurityKey: Enter your Azure security key in this setting.

  • auto-translate-json.azureRegion: Enter your Azure region in this setting.

DeepL Free

  • auto-translate-json.deepLFreeSecurityKey: Enter your DeepL Free security key in this setting.

DeepL Pro

  • auto-translate-json.deepLProSecurityKey: Enter your DeepL Pro security key in this setting.

Open AI

  • auto-translate-json.openAIKey: Enter your OpenAI security key in this setting.

Open AI Local server

  • install https://jan.ai/
  • download model mistral-ins-7b-q4
  • run server http://localhost:1337/v1 with model mistral-ins-7b-q4
  • set up extension parameters
  • auto-translate-json.openAIKey: whatever ;-)
  • auto-translate-json.openAIBaseURL: http://localhost:1337/v1
  • auto-translate-json.model: mistral-ins-7b-q4
  • auto-translate-json.maxTokens: 4096 We do not pay per token because it runs locally ;-)

Mode

  • auto-translate-json.mode: Enter "file" if translations are files in same folder like "en.json" or "folder" if translation files are in sub folders like "en/translation.json"

Start delimiter

  • auto-translate-json.startDelimiter: Start delimiter for named arguments. Defaults to "{" if you use ngx-translate or ngx-transloco you should use "{{"

End delimiter

  • auto-translate-json.endDelimiter: End delimiter for named arguments. Defaults to "}" if you use ngx-translate or ngx-transloco you should use "}}"

Ignore prefix

  • auto-translate-json.ignorePrefix: Translation keys that starts with ignore prefix will be ignored

Limitations

  • files must be named with the locale code that may be different depending on the translation service that you use. Please see the supported languages above.

  • OpenAI currently supports only translation from English to other languages!

Prices

  • Google

https://cloud.google.com/translate/pricing

  • AWS

https://aws.amazon.com/translate/pricing/

  • Azure

https://azure.microsoft.com/en-us/pricing/details/cognitive-services/translator/

  • DeepL

https://www.deepl.com/pro?cta=header-prices

  • OpenAI

https://openai.com/pricing

WARNING

Keep your keys safe!

auto-translate-json's People

Contributors

codegrue avatar deining avatar dependabot[bot] avatar gajo357 avatar notreessupport avatar topce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

auto-translate-json's Issues

transalate only some key:value

Hi and thanks for your extension.

Does it a way to transalate only value wich match some key instead of the whole file ?

Thanks

Translate to en-GB fails?

Awesome plugin, thanks for writing. Just one issue I've experienced: trying to translate from en.json, (American) English, to en-GB.json, British English, seems to fail. Message: "AutoTranslateJSON: en-GB is not supported. Skipping." It does work for other locale-specific languages like zh-TW.json, and en-GB does appear to be the correct language code according to Google's API docs. I've also tried en-UK, en-BR and for good measure.

Proposal for additional settings/features

Hi there,

the plugin is already very helpful, however I would like to propose the following additional features:

1. Allow for input file name customization

Currently the plugin is looking for en.json only. It would be great to customize this as my files have a intl_ in front of it.

2. Allow for input file extension customization

Currently the plugin is looking for json only. It would be great to customize this as my files are ending in arb, which is essentially a json file.

3. Add filter options

Currently the plugin is looking for translating each and every string, but I would like to be able to define filters so that some strings to not get translated. Particularly, some of my strings look like this "@testString": {...}. I would like to filter out everything starting with @.

Do you think there is a chance to get this implemented?

Support for subfolders

Hi

Is there any chance to implement the support for the structure

  • locales
    • en
      • translation.json
    • es
      • translation.json
        ...

I can help to implement it?

Bengali translations do not work via extension

But they seem to work correctly when using the auto-translate-json-library directly.
The extension shows that translations are added, but nothing happens.
Also, no errors in the console, and no way to debug it seems.
CAn you please help?

Json Format modified during translating process

Hi @codegrue :)

Thx for your vscode addon !

I have a question for you. I think, have i a bug during a translation.

First, under vscode have i this error :
AutoTranslateJSON: text.match is not a function
AutoTranslateJSON: Cannot read property 'match' of null

i tried to find more information about this, but unsuccessful.

Second things,
Between the original et translated files some differences appear. For Exemple :

Original File :

{
"key": "s2",
"title": "Let the Show Begin",
"description": "Summons water droplets resembling musical notes that form a Melody Loop, dealing Hydro DMG to surrounding enemies and afflicting them with the Wet status.",
"abilities": [
{
"name": "Melody Loop",
"description": null,
"descriptions": [
"Barbara's Normal Attacks heal all party members and nearby allied characters for a certain amount of HP, which scales with Barbara's Max HP.",
"Her Charged Attack generates 4 times the amount of healing.",
"Regenerates a certain amount of the current character’s HP at regular intervals.",
"Applies the Wet status to the character and enemies who come in contact with them."
]
}
]
}

Translated File :

"1": {
"key": "s2",
"title": "C'est parti pour le show ♪",
"description": "Invoque des gouttelettes d'eau ressemblant à des notes de musique qui forment une boucle de mélodie, infligeant des DMG Hydro aux ennemis environnants et leur attribuant le statut Trempé.",
"abilities": {
"0": {
"name": "Boucle de mélodie",
"description": null,
"descriptions": {
"0": "Les attaques normales de Barbara soignent tous les membres du groupe et les personnages alliés à proximité pour une certaine quantité de HP, qui évolue avec les HP Max de Barbara.",
"1": "L'effet des soins est multiplié par 4 avec les attaques chargées.",
"2": "Régénère à intervalles réguliers une certaine quantité de PV du personnage actuel .",
"3": "Barbara trempe les personnages et les ennemis avec qui elle entre en contact."
}
}
}
}
In bold the famous differences

In this archive the original and translated file :
i18n.zip

If you have some question for this issue, don't hesitate 👍

Best regards,
Therealcorwin.

Keep numbers

When there is a number in the file as
"code": 15

It simply gets deleted from the file. Can we add a check for numbers and simply not invoke the translate function?

Add DeepL

It'd be very useful if you could add DeepL PRO and DeepL Free as an option as well.

Thanks

Nothing Happens

I entered my OpenAI key, created a blank fr.json file, right-clicked my en.json file and ran the extension using the defaults.

image

It immediately says it worked (which is clearly a sign it didn't) and the fr.json file is empty.

image

Deep LFree configuration

Hi

I set in config Auto-translate-JSON: Deep LFree Secret Key , but when I try to run AutoTranslate said: "You must provide a Google, AWS or Azure parameters..."

But I want to use DeepL!

OpenAI is not working

I have an API key added to the OpenAI field in the extension but it doesn't seem to be working. I'm using the same setup for Google Translation and it works perfectly fine.

Also is it possible to add a custom prompt for GPT to have more context?

result.replace is not a function

When trying to translate using Azure, after entering the key and region germanywestcentral, I will always get the error message:

AutoTranslateJSON: result.replace is not a function

This happens on different computers and under Windows as well as Linux. Any ideas?

I can also provide the key as private message if required...

Thank you!

Peter

Wrong endpoint for DeepL free API

I tried using the DeepL free api, i got error in the log

Error: getaddrinfo ENOTFOUND api.free.deepl.com at Function.AxiosError.from

The endpoint being used is "api.free.deepl.com"

but on the website the endpoint is "api-free.deepl.com"

Named arguments should not be translated

I am using flutter plugin Easy Localization which supports named argument.

In my en-US.json, I have an entry:
"test": "Zip code {zip} is in {city}, {state}.",

After running 'Auto Translate JSON' using the extension in VSCode, it got translated in es.json as:
"test": "El código postal {zip} está en {ciudad}, {estado}.",

Named arguments should never be translated i.e. {city} should remain as is rather than becoming {ciudad}, and {state} shouldn't become {estado}.

Arrays are not preserved

"options": [
        {
          "value": "M",
          "text": "Male"
        },
        {
          "value": "F",
          "text": "Female"
        },
        {
          "value": "U",
          "text": "Prefer not say"
        }
      ]

became

 "options": {
        "0": {
          "value": "M",
          "text": "Homme"
        },
        "1": {
          "value": "F",
          "text": "Femme"
        },
        "2": {
          "value": "U",
          "text": "Je préfère ne pas préciser"
        }
      }

and thus break the underlying code.

Unable to translate any language.

I am using json files created by abp.io for my language files. A sample one is below. I have entered my Azure region and secret key. All other settings default. When I try to translate, it states Translations have been added to the files, but it comes back too fast, no way it can translate my files in that time. Upon check the different language files, no translations have been applied.

You will notice the json file has comments, but I have tested both with and without the comments, the results are the same.

{
  "culture": "en",
  "texts": {
    //
    // General
    //
    "IsActive": "Active",
    "NotSelected": "Not Selected",
    "FastCash1": "Fast Cash 1",
    "FastCash2": "Fast Cash 2",
    "FastCash3": "Fast Cash 3",
    "FastCash4": "Fast Cash 4",
    "FastCash5": "Fast Cash 5",
    "FastCash6": "Fast Cash 6",

    //
    //  Category
    //

    "Categories": "Categories",
    "NewCategory": "New Category",
    "EditCategory": "Edit Category",
    "CategoryName": "Category Name",
    "DisplayOrder": "Display Order",
    "DefaultCourse": "Course",
    "DefaultPrintQueue": "Print Queue",
    "BackgroundColour": "Background Colour",
    "ForeColour": "Foreground Colour",


    "ConfirmDeleteCategory": "Are you sure you want to delete Category with name {0}",

    //
    //  Printer
    //

    "Printers": "Printers",
    "NewPrinter": "New Printer",
    "EditPrinter": "Edit Printer",
    "PrinterName": "Printer Name",
    "PrinterType": "Type",
    "PrinterAddress": "Printer Address",

    "Enum:PrinterType:0": "Local",
    "Enum:PrinterType:1": "TCPIP",
    "Enum:PrinterType:2": "Queue",

    "ConfirmDeletePrinter": "Are you sure you want to delete Printer with name {0}",

    ///
    ///  Outlets
    ///

    "Outlets.Outlets": "Outlets",
    "Outlets.NewOutlet": "New Outlet",
    "Outlets.EditOutlet": "Edit Outlet",
    "Outlets.OutletName": "Outlet Name",
    "Outlets.UseMaps": "Use Maps",
    "Outlets.PromptForRoomGuest": "Prompt Guest Name",
    "Outlets.AskGuestCount": "Ask Guest Count",
    "Outlets.AddServiceCharge": "Add Service",
    "Outlets.HasRoomService": "Room Service",
    "Outlets.HasRegularGuests": "Regular Guests",

    "ConfirmDeleteOutlet": "Are you sure you want to delete Outlet with name {0}",

    //
    //  Terminals
    //

    "Terminals.Terminals": "Terminals",
    "Terminals.NewTerminal": "New Terminal",
    "Terminals.EditTerminal": "Edit Terminal",
    "Terminals.TerminalName": "Terminal Name",
    "Terminals.OutletName": "Outlet",
    "Terminals.PrinterName": "Receipt Printer",
    "Terminals.ServiceName": "Service",
    "Terminals.UseMaps": "Use Maps",
    "Terminals.FixedCashier": "Fixed Cashier",
    "Terminals.ShowServices": "Show Services",
    "Terminals.IsTouchScreen": "Is Touchscreen",

    "Terminals.CopiesReceipts": "Receipt",
    "Terminals.CopiesOrders": "Order",
    "Terminals.CopiesSummary": "Summary",
    "Terminals.CopiesPayin": "Pay-In",
    "Terminals.CopiesPayout": "Pay-Out",

    "Terminals.GridSize": "Grid Size",
    "Terminals.GridFontSize": "Grid Font Size",

    "Terminals.ConfirmDeleteTerminal": "Are you sure you want to delete Terminal with name {0}",

    //
    // Menu
    //
    "Menu:PoS": "Point of Sales",
    "Menu:PoS:Products": "Products",
    "Menu:PoS:Products:Categories": "Categories",
    "Menu:PoS:Settings": "Settings",
    "Menu:PoS:Settings:Printers": "Printers",
    "Menu:PoS:Settings:Terminals": "Terminals",
    "Menu:PoS:Settings:Outlets": "Outlets",


    //
    // Exceeptions
    //
    "PoS:00001": "There is already an Category with the same name '{name}'",
    "PoS:00002": "There is already an Printer with the same name '{name}'",
    "PoS:00003": "There is already a Terminal with the same name '{name}'",
    "PoS:00004": "There is already an Outlet with the same name '{name}'",


    //
    // Permimssions
    //
    "Permission:PoS": "Point of Sales",
    "Permission:PoS:Products": "Products",
    "Permission:PoS:Settings": "Settings"


  }
}

Is there anyway to debug the process or receive some logging so I can see what is happening and why it is not working.

Thanks

ignore words feature? or how to?

Sometimes, you have variable and replacement inside text.
like

"faq.4.title": "(ticketsicon) Ticket Shop",
"dialog.low.balance.special.offer.text": "Get {{offer}} coins for {{price}}",

(ticketsicon) it's will be replaced by css things.
{{offer}} to variable...

when translate {{offer}} is always OK.
but (ticketicons) it's translated on some languages...

how possible to handle it?

Azure translation returns json structure

Hi,

I'm trying to translate from en.json file to fr.json. I'm using the Azure translation service. It seems that Azure translation is not inserting only the translated text into the target language file, but it inserts the entire response json structure.

Example:
Source en.json
{ "info": "Click here for more info" }
Result:
{ "info": [ { "translations": [ { "text": "Cliquez ici pour plus d’informations", "to": "fr" } ] } ] }

The attached zip contains the source and result files:
translation_sample.zip

Plugin does nothing

Hey, so I set up everything. Followed all the instructions. But whenever I click auto translate it just does nothing. No error. No popup. Can't figure out what the issue is.

Issue with Deepl translation

Hi,
this is my input struture json:
{
"accountLayout": {
"myProfile": "My profile",
"myAddressBook": "My address book",
"vouchers": "Vouchers",
"myOrders": "My orders",
"myWishlist": "My wishlist",
"comparedList": "Compared list"
},
"trackOrder": {
"estimatedDelivery": "Estimated delivery",
"estimated": "Estimated",
"enterCode": "Enter the track code of your order",
"trackOrder": "Track Your Order",
"orderStatus": "Status of the Order",
"haveAnOrder": "Have an order? Want to know where your order is now?",
"knowProgress": "Know the progress of your product delivery."
},
"addressPopup": {
"country": "Country",
"order": "Order",
"state": "State",
"email": "Email",
"name": "Name",
"address": "Address",
"city": "City",
"zipCode": "Zip code",
"isRequired": "{type} is required",
"phone": "Phone",
"cancel": "Cancel",
"update": "Update",
"thisAddress": "{type} this address",
"saving": "Saving",
"save": "Save",
"message": "Message",
"addressPlaceholder": "Street address or P.O. Box",
"address2Placeholder": "Apt, suite, unit, building, floor, etc.",
"subject": "Subject"
},
........
.....

and I get output:
{
"accountLayout": {},
"trackOrder": {},
"addressPopup": {},
...
....
...
...
...
}

AWS access when MFA is enabled on the aws account

Getting this exception. I have the correct access key is and secret setup in the extension settings in vscode, but getting the below exception. Thoughts?
UnrecognizedClientException: The security token included in the request is invalid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.