Android Tutorial Activity Translation

Hey All

I have been looking around here for some kind of Modul/Lib for translation of an activity.

So I made this Modul to ease the pain.

This Modul translate your hole activity with everything in it.

This is how it works:

From the Designer you add a "key" to the TAG-field.

Create a TXT-file and put it in your project->FILES
Since this TXT-file is used as a MAP you can add the "key" = "Translation" as below:

!Uk-translation
bja = Confirm
bnej = Decline
lvelkommen = Welcome

Then its just 2 calls:

Translate.Init_File("language.dk")
Translate.ThisActivity(Activity)

And your up and running

Any suggestions is welcome :)

Ofc use the AHlocale to know what region/language to use.
 

Attachments

  • translate.zip
    7.3 KB · Views: 578

Cableguy

Expert
Licensed User
Longtime User
You didnt look hard enought...You can just use the AHLocale lib for this purpose, as it happens to have a built in translator.
 
Last edited:

Kimmowich

Member
Licensed User
Longtime User
Well..

Cant see how it can translate the hole activity by it self.

What I see is a great lib where you have to do it all your self regarding the translation.
 

Cableguy

Expert
Licensed User
Longtime User
Imagine you have a file, just like yours:

Welcome = Bemvindo
Today = Hoje
Tomorow = Amanha

after declaring the translator you can use:

label1.text=Translator.Get("Welcome")

And it will return the value for "welcome" in the current device language.

(Tis is just an example, the code may NOT be exactly this, but should be pretty close)
 

Valserwasser

New Member
Licensed User
Longtime User
Well..

Cant see how it can translate the hole activity by it self.

What I see is a great lib where you have to do it all your self regarding the translation.

Thank you Kimmowich! :icon_clap: I agree with you. AHlocale Lib is a great lib. But your module is unbeatable in terms of simplicity and user friendlyness.
Compared to your module, I found the syntax of the AHlocale's language file not very intuitive.

Example of AHlocale language file: First\ day\ of\ Week\:=Primo giorno della settimana\:

With your module you translate your whole application in one sweep! :sign0098:
 

ewe

New Member
Licensed User
Longtime User
Translation of Listview-Entries

Hi Kimmowich,

I load some texts into a listview via AddSingleLine("blabla") - is there a chance to translate this with your module?

Bye,
ewe
 

Kimmowich

Member
Licensed User
Longtime User
Hey Ewe

Everything is possible to translate..

First of all.. I assume you know the contents of the list.

It can only work if whatever text you need to translate have a reference-key.

If you know all that, I will be happy to help you out..

sincerly
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hey Kimmowich,

Smart and simple - I do like that. Nice work, indeed.

The only limitation I can see is when you already need Tag for your application
such as for quering Button Clicks using the Sender function or already occupied
Values in ListViews while Menus may require some more Oel :D

Oel drikker? You bet ;)

:sign0098:
 

Kimmowich

Member
Licensed User
Longtime User
hey Alfcen

Thanks for the words.

Yes it is simple and easy to understand.

Yes in certain rare (to me at least) situations, a combination of my module and AHlocale can solve the problems you get in to when the Tag-field is occupied for something else.

The thing is.. using Tag-field on labels, radiobuttons, togglebuttons, checkboxs for translations is straightforward and dosnt require the hard work of AHlocale and for most cases the buttons dosnt either.

Cheers ;)

:sign0008:
 

marbellapc

Member
Licensed User
Longtime User
Hello, really works well, I have only one query.
One could make when selecting a language that is maintained even if you close the application? and if possible do this, as it would accomplish? I've been looking but can not understand how to save the language.

The truth is that I liked it because it is easy and uncomplicated, but it would be a very good point to keep the selected language.

regards

P. S. And sorry for my English, I speak not fluently and I am using a translator.
 

marbellapc

Member
Licensed User
Longtime User
Well I just fix it for me, not if they be worth to others, but I explain what I did.
For indeed I have used StateManager to save the settings.

In Process_Global Dim I inserted a default value.
B4X:
Sub Process_Globals
   Dim lang As String : lang = 1 ' ---------------------------------- Indicamos el idioma por defecto de la aplicacion.
End Sub

In Activity_Create languages ​​and have indicated the variable lang
B4X:
Sub Activity_Create(FirstTime As Boolean)
' ----------------------------------------------------------- Creamos la variable para el idioma.    
    LFile(0) = "language.es"
   LFile(1) = "language.uk"
   Translate.File_init(LFile(lang))
   es = True
   Translate.ThisActivity(Activity)
End Sub

Then I created a CheckBox and a Checked If you indicated the value of languages​​.
B4X:
Sub CheckBox_lang_CheckedChange(Checked As Boolean)
   If Checked = True Then
      lang = 0
   Else
      lang = 1
   End If
   Translate.ThisActivity(Activity)
End Sub

This along with StateManager has been perfect.

Regards
 

Kimmowich

Member
Licensed User
Longtime User
Hey

Nice to read you find the module usefull :icon_clap:

Great you found an easy solution for saving the chosen language.
Otherwise you could have made a seperate "ini"-file for the settings.

Sincerly
 
Top