Tool MTrans - mini translator helper

Hi all,

I needed a small tool to handle localization of my app. I found several fine options in the forum, and while they seemed like very competent tools, my needs were more modest and I wanted a smaller solution. So I created it, and thought I'd share it in case someone might find it useful.

License:
I place MTrans in the Public Domain without a requirement for attribution. And I encourage its users to share their improvements back in this thread.​


Features:
  • No external dependencies
  • Very small codebase (~100 lines + actual translations)
  • Can translate everything in an Activity
  • Can translate specific terms, optionally with parameters
  • Support for default language
  • Easily control what views should be translated by prefixing their text with "mtr."

Documentation


activity(act As Activity)
Translates the title and all views in the activity.

get(text As String) As String
Translates the text using the default language. ("en_US" if not changed)

get2(text As String, params As List) As String
Translates the text using the default language, and performs parameter substitution.

get3(text As String, params As List, language As String) As String
Translates the text using the defined language, and performs parameter substitution.

setLanguage(language As String)
Sets default language. Note: One can use whatever one wants as language code. It just has to match what's actually used in the translation list in the internal wordMap.

Private fillWordMap
This is where one defines all translations. The key is formatted as <name><dot><language>. This is never called by your code, just add your translations to it. Examples for a phrase in three languages:

wordMap.Put("appname.en_US", "MTrans - mini translator helper") ' English
wordMap.Put("appname.sv", "MTrans - en liten översättare") ' Swedish
wordMap.Put("appname.de", "MTrans - Mini-Übersetzer Helfer") ' German


And an example for params:

wordMap.Put("paramtest.en_US", "First came {0}, then {1} and finally {2}.")

Known issues

ToggleButton translates just fine, as shown in the attached file. But for some reason it reverts back to its non-translated text once one toggles it. Very strange, and I don't know why. If someone can figure out how to fix it I'll update MTrans.​
 

Attachments

  • MTrans.zip
    10.6 KB · Views: 367
Top