Skip to content

Use Google Translation API to create i18n resource bundles.

License

Notifications You must be signed in to change notification settings

Bhlowe/translate-properties

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

translate-properties

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.

File Structure

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.

Running

From the command line are: Arg 1: path to properties file to translate Arg 2: Option list of language identifiers, comma separated.

Example

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.

Reference

This project uses Google cloud translate API . https://cloud.google.com/translate/docs/quickstart-client-libraries

Fixing the output

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.

Notes

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.

About

Use Google Translation API to create i18n resource bundles.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages