Android Tutorial [B4X] Localizator - Localize your B4X applications

Erel

Administrator
Staff member
Licensed User
B4J localizator converter v1.10 was released. It allows running the converter from the command line.
 

Erel

Administrator
Staff member
Licensed User
Automating the localizator

1. Add the xlsx file to the Files folder. This allows us to open the workbook directly from the IDE:



2. Add this custom build action:
B4X:
#CustomBuildAction: 1, c:\windows\system32\cmd.exe,/c java -jar C:\<path to converter>\B4XLocalizator.jar ..\Files\strings.xlsx ..\Files\strings.db
The Excel workbook will be converted each time the app runs.

Note that it requires B4J v6+, B4A v7.8+ (not yet released), B4i v4.8+ (not yet released).
Make sure to use the latest version of B4XLocalizator.jar.
 

Erel

Administrator
Staff member
Licensed User
It always better to start a new thread for your question.

Call Localize on each item when you add it to the spinner.
 

leitor79

Active Member
Licensed User
Hi! Is there a way to indicate a default key if the current locale is not defined? Or should I use the key names as default locale?

Thank you very much for sharing this!
 

leitor79

Active Member
Licensed User
Hy Luca, Thank you for your answer.

I've read that, but as I have my keys already defined I'd like to find the other way.

I've looking at the class code then, and I've found that "us" being the default locale when the current locale is not defined is already done:

B4X:
Locale = FindLocale
    If sql.ExecQuerySingleResult2("SELECT count(*) FROM data WHERE lang = ?", Array As String(Locale)) = 0 Then
        Log($"Locale not found: ${Locale}. Switching to 'en'."$)
        Locale = "en"
    End If
    Log($"Device locale: ${Locale}"$)
    LoadStrings
Regards!
 

emexes

Well-Known Member
Licensed User
I would like to use it.
Could you give a reference?

Is it this one, that you would recommend?
View attachment 53254

edit:
Un-be-lie-va-ble. This is a huge timesaver.
I am a bit late to this party, but: I agree, this technique is brilliant. A project I worked on few years back, we used the GOOGLETRANSLATE function directly, and had three columns for each language:

eg, if column A is key, column B is original language, then for columns C,D,E for the first translated language:

- the first column was the translation eg =GOOGLETRANSLATE($B3,$B$1,C$1)
- the second column translated it back to the original language eg =GOOGLETRANSLATE(C3,C$1,$B$1)
- the third column was either the translation, if it was unchanged after being translated back to the original language, or blank
eg =IF(D3=$B3,C3,"")

and then for each language we'd sort by the last column and print the original and three translation columns for all the mangled items, and give it to the relevant language speaker (eg, my dad for German, my ex-wife for French, the Chinese lady at the lunch shop for Mandarin...) to check.

Then we'd enter the corrected translations into the language last column, and pull the required columns into another page and save that page for "compilation" for use by the program's localization routine.

I have a vague recollection of a routine called Translate012(PhraseKey, Quantity) that would find the required translation using PhraseKey, and then use that line or one of the next two, depending on the Quantity, so that you'd have messages like:

Translation file:
Line 35: "VehiclesAvailable", "No vehicle found"
Line 36: "", "One vehicle found"
Line 37: "", "$Q$ vehicles found"

Program output:
Translate012(VehiclesAvailable, 0) = "No vehicle found"
Translate012(VehiclesAvailable, 1) = "One vehicle found"
Translate012(VehiclesAvailable, 17) = "17 vehicles found"

and the three messages could be wildly different, eg:

Translation file:
Line 35: "VehiclesAvailable", "NO vehicle is available :-("
Line 36: "", Just one vehicle left, so be quick!!!"
Line 37: "", "Multiple vehicles are available (would you believe $Q$?)"

and some other variations of Translate routines that would substitute strings in at placemarkers, so that, for example, adjectives could go before nouns in English ("the $C$ car" = "the red car") and after nouns in French ("la voiture $C$" = "la voiture rouge"). The Chinese lady would um and ah a lot, but our Chinese customers were rapt, one went so far as to say it was easier to read and use than "real" Chinese software (at least, we think that's what he said ;-)
 

noeleon

Member
Licensed User
i just noticed the view texts with csbuilder value are converted to plain string. Is there a way to localize them too?
 

Erel

Administrator
Staff member
Licensed User
You will need to localize the text that you use while building the CSBuilder.

B4X:
Dim cs As CSBuilder
cs.Initialize.Color(Colors.Red).Append(loc.Localize("some text")).PopAll
 
Top