Translating i18 resource bundle property files using google api
Inspired by https://github.com/shantonav/translation
##Requires GOOGLE_API_KEY environment variable set to valid API key.
The layout of resource bundles for i18n translations is: filename.properties # This is the file you add key=value strings for translation filename_en.properties # This file is generated by the app and is used to know which strings have changed. filename_xx.properties # auto-generated files for each language you want translations for.
From the command line are: Arg 1: path to properties file to translate Arg 2: Option list of language identifiers, comma separated.
TranslateProperties.main("src/main/resources/xyz/filename.properties", "es,de,fr");
Should generate files
src/main/resources/xyz/filename_es.properties src/main/resources/xyz/filename_de.properties src/main/resources/xyz/filename_fr.properties src/main/resources/xyz/filename_en.properties
Where filename_en.properties is a copy of base.properties used to keep track of changes since last run.
Default mode is to only update existing translations when the english version changes.
When you edit or add to "test/base.properties" and run TestPropertFileTranslation, changed strings will be re-translated.
This project uses Google cloud translate API . https://cloud.google.com/translate/docs/quickstart-client-libraries
Translations are not perfect - Getting spaces before and after escaped characters, for instance:
TEST_NEWLINE=Danke dir \n Bitte.
TEST_STRING=Hallo %s !
Added a new class called FixTranslation to help reduce the translation mistakes that are created.
This is just a quick project to translate some strings used in an app. I'm sure better systems exist.. Comments and PR's welcome.