App localization - languages.

cimperia

Active Member
Licensed User
Longtime User
Ehi, @cimperia, ho finalmente finito l'app e adesso mi apprestavo a pubblicarla e poi a rileggere bene il tuo post ma l'hai eliminato :(. Grazie, comunque.

Sorry, I deleted it as there was no reaction to it and thought it might be irritating, as I was pushing towards a direction that it is not the one you were taking. I am happy to post it again:

I think I was not clear enough. I made two distinct possible suggestions:

1. Leave your database and application as is, but add the facility from your DB manager to generate code. It’s a one-off generation of code that is then copied into our own application.

Example:

The database contains:

EN IT FR

Name nome nom
Password password mot de passe
Date of birth data di nascita date de naissance
Gender genere sexe

You would then offer the possibility, by pressing a button, to generate the following code (or something similar):

B4X:
Sub Process_Globals
  Dim translate_map As Map
EndSub


Sub PopulateTranslate

  translate_map.Initialize

  Dim NAME As Int = 0
  Dim PASSWORD As Int = 1
  Dim DATE_OF_BIRTH As Int = 2
  Dim GENDER As Int = 3

  Dim line_map As Map

  line_map.Initialize
  line_map.Put("EN", "name")
  line_map.Put("IT", "nome")
  line_map.Put("FR", "nom")
  translate_map.Put(NAME, line_map)

  line_map.Initialize
  line_map.Put("EN", "password")
  line_map.Put("IT", "password")
  line_map.Put("FR", "mot de passe")
  translate_map.Put(PASSWORD, line_map)

  line_map.Initialize
  line_map.Put("EN", "date of birth")
  line_map.Put("IT", "data di nascita")
  line_map.Put("FR", "date de naissance")
  translate_map.Put(DATE_OF_BIRTH, line_map)

  line_map.Initialize
  line_map.Put("EN", "gender")
  line_map.Put("IT", "genere")
  line_map.Put("FR", "sexe")
  translate_map.Put(GENDER, line_map)
End Sub

It would be easy within your DB Management to implement such functionality as in a nutshell it's a matter of iterating the rows of the database.

The output code would be copied into our own application and to retrieve a translation we would need something like:

B4X:
  Dim s As String = Translate.Tr2(PASSWORD)

That means you'd need to add a second method (Tr2) for this method to work seamlessly with your class. The Tr2 method, would like your current TR method choose the correct translation by checking the current language setting.

The user class that you would provide would be of course aware of translate_map, accessible from anywhere as it is a Process Global. If you don’t like the Process Global, you can change the call so as to pass the Map, something like:

B4X:
Dim s As String = Translate.Tr2(PASSWORD, translate_map).

There are two cons with this:
1. It's not scalable, i.e. it's strictly a local solution, but I understand it's what you're aiming for?
2. One has to remember to regenerate and copy the code after each database change.

The pros:
Very fast
No need to copy the database with our own application.


2. I offered a second solution which requires a database change. I can post a more detailed suggestion (with SQL statements). This second solution will keep the unique keys as in your original implementation. Let me know if you're interested as I don't want to pollute your thread.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
More easy and quick now, with Translation.Tr2(Activity) (or Translation.Tr2(YourPanel))
It translates texts you added by Designer (you don't need to write code line like: Button1.Text = Translation.Tr("Close")
But you can still translate all texts in your app using Translation.Tr, not only views' texts)

 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
@cimperia , about your suggestions:

They are really interesting.
Since it seems that no one needs this tool and because, finally, I want to devote time only to my super millionaire app :p, I think I do not spend any more time on this topic.

However, thank you very much.
 
Top