Android Tutorial [B4X] Localizator - Localize your B4X applications

Eme Fibonacci

Well-Known Member
Licensed User
Another silly question...

Can the xls file have empty rows? in long files it would help create separation between "topics"

[edit] tested with success!!!
You can use this code line from @Erel to add comment lines in the worksheet.

B4X:
If row.GetCell(0).ValueString.StartsWith("'") Then Continue
see above.
 

trueboss323

Active Member
Licensed User
When using the LocalizeLayout how do I know which keys are assigned to which? In the example, how does it determine Label1, Label2, Label3 equals one two three? Do the text of the labels have to be the same as the keys?
 

Erel

Administrator
Staff member
Licensed User
You can see it in the code:
B4X:
Public Sub LocalizeLayout(PanelOrActivity As Panel)
   For Each v As View In PanelOrActivity.GetAllViewsRecursive
     If v Is Label Then 'this will catch all of Label subclasses which includes EditText, Button and others
       Dim lbl As Label = v
       lbl.Text = Localize(lbl.Text)
     End If
     If v Is EditText Then
       Dim et As EditText = v
       et.Hint = Localize(et.Hint)
     End If
   Next
End Sub
The text should match the keys.
 

trueboss323

Active Member
Licensed User
I'm having a strange problem Erel. My text isn't getting localize even when I put Starter.loc.LocalizeLayout. The strange thing is that when I put a breakpoint on that line , and then continue running, the text is localized. This doesn't happen when I don't put a breakpoint, like it ignores that line. Why does this happen?
 

trueboss323

Active Member
Licensed User
Here you go Erel. I tried testing this with only the French language. Only the 'days','hours', 'minutes' labels should be in French. And i put the LoadLayout line right at the end of the ActivityCreate sub.
 

Attachments

Erel

Administrator
Staff member
Licensed User
The views inside the view pager cannot be reached directly. You need to add:
B4X:
For Each pnl In vp.Panels
   Starter.loc.LocalizeLayout(pnl)
Next
 

trueboss323

Active Member
Licensed User
That seemed to fix the problem, thank you Erel! How could I also do the same with Tabstrip? I don't see a method to get panels from it.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Put the views of each tab in a panel and then you will be able to call it with:
B4X:
For Each pnl In Array(MainPanel1, MainPanel2, ...)
 Starter.loc.LocalizeLayout(pnl)
Next
 

corwin42

Expert
Licensed User
Finally I took the time to test this translation method and I like it very much.

Some notes and tipps:
  • The precompild B4XLocalizator.jar did not work for me. It opens a complete white window. I compiled it myself and then it works well.
  • The heading in the first column MUST be "key" otherwise wrong translations are generated.
  • I use Google Docs SpreadSheets for translation. There is a really nice plugin called "Easy Translations". It uses the exact same format for the sheet and can automatically generate missing translations from Google Translator. This is really great.
    Additionally it is possible to share the document and restrict editing access to single language columns to other users. With this feature it is possible to give other translators access to just one language. So this can be used as a simple community translation service.
 

fredo

Well-Known Member
Licensed User
There is a really nice plugin called "Easy Translations".
I would like to use it.
Could you give a reference?

Is it this one, that you would recommend?
27-02-_2017_10-57-39.jpg

edit:
Un-be-lie-va-ble. This is a huge timesaver.
 
Last edited:

DavideV

Active Member
Licensed User
Hello,
i need to retrieve a list or array of iso codes present in the created database to let the user choose his preferred language from the app settings.
Unfortunately i'm not familiar with SQL so i don't know how to query them.

A new sub in the Localizator class that returns that values (isocodes) will be great :)

Thanks in advance
DavideV
 

DavideV

Active Member
Licensed User
1. You should create a new thread for your question as it has nothing to do with this thread.
2. Read the beginners guide and users guide. There are Database sections in it too
DonManfred,
1) my question is related to the Localizator class in this thread, why do i need to create a new thread?
2) will do, thanks for help
 

LucaMs

Expert
Licensed User
Hello,
i need to retrieve a list or array of iso codes present in the created database to let the user choose his preferred language from the app settings.
Unfortunately i'm not familiar with SQL so i don't know how to query them.

A new sub in the Localizator class that returns that values (isocodes) will be great :)

Thanks in advance
DavideV
It seems to me that the class does not contains such data and the db is created from an excel file that you should create.

You can get that data (and many other) using the AHLocale library.
 

DavideV

Active Member
Licensed User
It seems to me that the class does not contains such data and the db is created from an excel file that you should create.

You can get that data (and many other) using the AHLocale library.
Hi Luca,
maybe i'm not clear, i don't need the device locale but the isocodes present in the db created by the b4J utility by Erel (first post).
I think it should contains these info and maybe obtained by a query
 

LucaMs

Expert
Licensed User
Hi Luca,
maybe i'm not clear, i don't need the device locale but the isocodes present in the db created by the b4J utility by Erel (first post).
I think it should contains these info and maybe obtained by a query
I have never used this tool* but if I understand it it will convert your excel file into a SQLite db, so it will only contain the languages already included in the Excel file.
Maybe you just want this; in this case you could add this routine to the Localizator class:
B4X:
Public Sub GetLanguages As List
    Dim lstLanguages As List
    lstLanguages.Initialize
    Dim rs As ResultSet = sql.ExecQuery("SELECT lang FROM data GROUP BY lang")
    Do While rs.NextRow
        lstLanguages.Add(rs.GetString("lang"))
    Loop
    rs.Close
    Return lstLanguages
End Sub

* Probably because I like this one:
https://www.b4x.com/android/forum/threads/lmtranslationdbmanager.58660/
:)
 
Last edited:

DavideV

Active Member
Licensed User
I have never used this tool* but if I understand it it will convert your excel file into a SQLite db, so it will only contain the languages already included in the Excel file.
Maybe you just want this; in this case you could add this routine to the Localizator class:
B4X:
Public Sub GetLanguages As List
    Dim lstLanguages As List
    lstLanguages.Initialize
    Dim rs As ResultSet = sql.ExecQuery("SELECT lang FROM data GROUP BY lang")
    Do While rs.NextRow
        lstLanguages.Add(rs.GetString("lang"))
    Loop
    rs.Close
    Return lstLanguages
End Sub

* Probably because I like this one:
https://www.b4x.com/android/forum/threads/lmtranslationdbmanager.58660/
:)
Hi Luca,
it is exactly what i need, works perfect, useful answer :)

It is a pity i can't put more than one like ;)

Thanks
 
Top