Android Tutorial [B4X] Localizator - Localize your B4X applications

Erel

B4X founder
Staff member
Licensed User
Longtime 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. Updated command that works with Java 8+:
B4X:
#CustomBuildAction: folders ready, C:\Users\H\Downloads\B4XLocalizator.jar, ..\Files\strings.xlsx ..\Files\strings.db
 
Last edited:

leitor79

Active Member
Licensed User
Longtime 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
Longtime 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

Expert
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

Active 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?
 

so27

Active Member
Licensed User
Longtime User
When I want to start the B4Xlocalizator, it is missing libraries. Where can I get these?

 
Last edited:

Serge Bertet

Active Member
Licensed User
When using this class in a B4X Pages app,
this component :

turned into this :

the workaround is to add a line in the LocalizeLayout sub like this :
B4X:
Public Sub LocalizeLayout(PanelOrActivity As Panel)
    For Each v As View In PanelOrActivity.GetAllViewsRecursive
'        Log(GetType(v))
        If v Is Label Then 'this will catch all of Label subclasses which includes EditText, Button and others
            Dim lbl As Label = v
            If lbl.Text = "Made with " & Chr(0xF004) & " in B4X" Then Continue ' <== line added
            lbl.Text = Localize(lbl.Text)
        End If
        If v Is EditText Then
' etc...

For sure this will not solve the problem (if any) for B4J and/or B4I
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…