Hi!
As i got so many help from this forum, i thought that I have to give something back
This is a small class that will help you to translate you app. It makes use of the strings.xml file located in your res/values folder.
You can use the strings.xml file with services like getlocalisation.com
This class needs Reflection library!
Documentation:
(done with warwound's B4A library and module reference generator.)
ahaTranslate
Have fun, I hope you like it
-----
Version 1.2
Added: New GetResourceDrawable (Key As String) As Object
Loads the drawable from the ressources directory (res/drawable) . Use res/drawable-de etc for localisation
(Works for 9patch images as well)
Version 1.3
Added: GetAndroidDrawable
As i got so many help from this forum, i thought that I have to give something back
This is a small class that will help you to translate you app. It makes use of the strings.xml file located in your res/values folder.
You can use the strings.xml file with services like getlocalisation.com
This class needs Reflection library!
B4X:
'USAGE:
'------
'You need at least one "strings.xml" - file in the Folder "objects" - "res" - "values"
'Remember to to set this file to read only!!
'To add another language, create a new folder in the "res" directory, named "values-" and the 2 letter abbreviation of the language
'You can find the 2letter abbreviations here: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
'Example: "values-de" for german. In this directory, place the localized "strings.xml" - File (Full path: objects/res/values-de/strings.xml"
'Tipp: Services like http://www.getlocalization.com/ can use this xml - files :)
'Sample Layout of the "strings.xml" file:
'<?xml version="1.0" encoding=\"utf-8\"?>
'<resources>
' <String name="app_name">ahaTranslate</String>
'</resources>
'TIPP:
'Do you want a localized AppName? Go to the Manifest-editor and replace:
' SetApplicationAttribute(android:Label, "$LABEL$")
'with
' SetApplicationAttribute(android:label, "@string/app_name")
'Of course, you have to define the app_name in strings.xml as shown above in the Sample Layout
'Info about Translation: http://developer.android.com/guide/topics/resources/localization.html
'http://developer.android.com/guide/topics/resources/string-resource.html
(done with warwound's B4A library and module reference generator.)
ahaTranslate
- AutoTranslateActivity (Activity As Activity)
Translates a whole activity. The Tag information of the controls is used. The tag corresponds to the name in the strings.xml file
Supported: label, button, checkbox, edittext, radiobutton, togglebutton, spinner
ATTN: ToggleButtons have to states. ON and OFF. If you use "togglebuttontext" as key in the Tag-Property, you must have 2 Strings in the strings.xml file:
togglebuttontextON and togglebuttontextOFF! - GetDeviceDateFormatSettings As String
Gets the phone Date Settings' returns "MM/dd/yyyy" on error - GetPhoneCurrencySymbol As String
Gets the phone currency Symbol. If it's not found, $ is returned - GetPhoneLanguage As String
Gets the phone language and returns the 2-Letter Code (en for english, de for German..)
If language cannnot be determined, 'en' is returned
Returned string is lowercase - GetResourceBitmap (Key As String) As Bitmap
Loads the drawable from the ressources directory (res/drawable) and returnes a bitmap. Use res/drawable-de etc for localisation - GetResourceString (Key As String) As String
Gets the translation for a specific key
If no localized String is found, the appropiate String from "values/strings.xml" is is used.
If the Key doesn't exists, it returns "No translation found!" - GetResourceStringArray (Key As String))
Gets an StringArray
If no localized StringArray is found, the appropiate StringArray from "values/strings.xml" is is used.
If the Key doesn't exists, it returns "No translation found!" - GetResourceStringPlural (Key As String, Count As Int) As String
Gets localized Plurals. You have to pass the Count. For example:
count = 1: Returns day
count =>2: Returns days..
See String Resources | Android Developers => Quantity Strings for more information - GetResourceStringWithParams (Key As String, Params As List) As String
Gets the translation for a specific key with the use od Parameters.
string.xml: <string name="Hello">Hi {1} {2}!</string>
B4A: GetResourceStringWithParams("Hello",Array As String("World","")
=> Returnes: Hi World
If no localized String is found, the appropiate String from "values/strings.xml" is is used.
If the Key doesn't exists, it returns "No translation found!"
Have fun, I hope you like it
-----
Version 1.2
Added: New GetResourceDrawable (Key As String) As Object
Loads the drawable from the ressources directory (res/drawable) . Use res/drawable-de etc for localisation
(Works for 9patch images as well)
Version 1.3
Added: GetAndroidDrawable
Attachments
Last edited: