I want to use RB's Dynamic Strings to have different languages for any given string. I want the user to be able to change their language preference in the program and I want the dynamic strings to reflect the selection. Is there a way to have it done while the program is running or do I need to restart the program?How do I do it?Thx for all the help I get here.
It can be done but there are a couple of ways. I too wanted to do a on-the-fly langauge change and I foudn out that the best way without rebooting the program is to set in each commands as LangList. Lets take a simple StaticText field with a buligual language list optionAPP. Property:LangSet as Integer = 0Set a menu item to include a Language option then when a language is selected set the App. LangSet to the correct integer you have selected for it. App. LangSet = 0 // Default EnglishApp. LangSet = 1 // Spanish or what language you so chooseApp. LangSet = 2 // Add as many as you like... StaticText1. Activate:
// Check to see which Language is selectedIf App. LangSet = 0 then // English Me. Text = "This will allow you to select a language of your choose."Elseif App. LangSet = 1 then // Spanish Me. Text = "Este permitirá que usted seleccione una lengua de su elegir."Elseif App. LangSet = 2 then // Note you can continue with as many languages as you need Me. Text = "?"End
You will only need to add this to the commands that shows text within your app as the user input will already be in there native langauge. This will work as when the user selects a new language it will the reset in the commands Activate section. PushButton1. Activate:
// Check to see which Language is selectedIf App. LangSet = 0 then // English Me. Caption = "Yes"Elseif App. LangSet = 1 then // Spanish Me. Caption = "Si"Elseif App. LangSet = 2 then // Note you can continue with as many languages as you need Me. Caption = "?"End
I had this problem and made this and it works fine : 1-I creates two global variables : langueCompilation (a string) and WordsLocalisazion( array of strings)2- I made a global method Localisazion hereunderSub Localisazion(windowPouet as window)Dim i as integer '--- select case langueCompilation case "french" i=1 case "english" i=2 case "spanish" i=3 case "cymraeg" i=4 case "russian" i=5 end select '-------------------------------------------- ' For the menus '-------------------------------------------- AppleAboutApplication. Text=nthField("A propos de KnotsBag ;About KnotsBag ;Acerca de KnotsBag ;Ynglŷn â KnotsBag;Что такое KnotsBag ;new language words ",";",i) '-------------------------------------------- ' For the windows '-------------------------------------------- select case windowPouet' case WindowPreferences ' redim WordsLocalisazion(4) '--- WordsLocalisazion(0)=nthField("Langues;Languages;Linguas;Leithoedd;Язык",";",i) WordsLocalisazion(1)=nthField("Ouvrir document récent;Open recent item;Abrir reciente;Agor dogfennau diweddar; Открыть документ ",";",i) WordsLocalisazion(2)=nthField("Police;Font;Fonte;Ffont;Шрифт",";",i) '--- WordsLocalisazion(3)=nthField("Nettoyer;Clean;Limpiar;Glanhau;Удалить",";",i) '--- WordsLocalisazion(4)=nthField("Taille;Size;Tamaño;Maint;Размер",";",i) ' case otherwindow 'redim WordsLocalisazion(n)'---WordsLocalisazion(0)=WordsLocalisazion(1)=... WordsLocalisazion(n)='--- ' end selectAfter that you just have to call this method every time you change the language and everytime you open a window. In the open event of the window you write :Localisazion 'call to the methodwindowobject0 text=WordsLocalisazion(0)windowobject1 text=WordsLocalisazion(1)'''windowobjectn text=WordsLocalisazion(n)This way present one big advantage : you can send the text of this file to a friend to translate it in any text editor. He just has to change the words 'new language words' in his own language. HTH !Géraud (
I think there is an easier way to handle different languages. The ways described here so far include all of the texts within the program. When you have lots of text the program well grow bigger and bigger and could clog up your code. Here is a method I already applied in a couple of Visual Basic programs. Without going into the actual code needed in RB (I don't have the time to write it now) here is the procedure and I think you can grab the idea. I work with external text files for each language but it could be done in one file as well. Think of it then like in a spreadsheet :1OpenOuvrirAbrir….2SizeTailleTamaño...3CloseTerminerTerminar…… and so onYou use an array of strings. Only you have to know each string's "position". Let's say you have up to 200 words or even sentences. Dim text(200) as string. When the user chooses or sets a language you keep track of that in a setup file. Normally your program will use such a file to store all the user's preferences. Or you could use the above pushbutton example given by Jonathon. When your program starts it looks for what language is wanted and reads the list of strings accordingly. Let's say you loaded the French list then text(2) contains "Taille"In any of the above examples you now only need a single line of code for example :me text = text(2) // the user will see TailleGet the idea ?
Well so you are saying to create an external langauge file something like lang ini?The file will have rows that contain the language data seperated by comas. Yes. SiNo. Noetc... But how are you going to get teh right data? Need some kind of marker. Then a true INI file might work better as how an INI is setup that is and NOT a true INI. FILE[LANG] <- This is where the Languages are added so that it is all controled via this INI file. This also can be accessed when the program starts by adding the current languge available in a PullDown MenuOption or ComboBox. English. Spanish etc...[T001] <- This would be the Control that would require to have language text Translated. This case an Editfield. Yes. Si[T002]No. No[T003]etc... This would put the bulk of the language translation coding in a seperate file. And you are right as in a large program the languge translation code would take up half of the project code. But no matter what is done for the control to know what language is selected and then to select the correct text for the control is the biggest problem as there is no easy way of doing it. So you are right as it will tae 2 parameters to do this.1. What language was selected!2. When the Control(editfield statictest pushbutton etc...) is opened select the correct languge text for that control. The Language Data is just that. DATA and it can be stored anywhere. And if contained in a seperate file it can be changed without re-compiling the whole program again. My way works but it is not very practical as you would have to re-compile your project every time you add or changed a language text. The lang ini file is something that is easily changed and without alot of re-compiling. My new example would allow the lang ini file have the Language Choice Selections(English spanish etc...) and the Translations(Yes. Si; No. No....)Now the only thing would be to set each Control to the correct code in the lang ini file. Example:Editfield1. Open
Dim tc tt as Stringtc = "[T001]" // tc = Translation ControlApp. Lang = 0 // Default is English which is set to = 0// Find the Control within the lang ini file. Using the tc variable....// Once file has been found get the translation text.. me text = tt // tt = Translation Text
There are some good code examples for creating INI files that can be used. Remember that htis is NOT going to be a true INI but we are using the internal code and modifing it to work. Also we can name the file anthing we like as I just used lang. INI you can use lang tlc (Translation Language Code) if you want.
Tim,Thanks for the input and I was wanting to know would a Library work and does it create a seperate file that would not be apart of the final project code?I am very new to Library in RB
I think you mean Dictionary. The simplest approach would be to have a text file with source/translation pairs:Yes<tab>OuiOpen<tab>OuvrirPlease press return<tab>whatever it would beYou can easily read such a file and load it into a dictionary.
while not inFile. EOF s= inFile. ReadLine sArray = Split(s chr(9)) langDictionary. Value(sArray(0)) = sArray(1)wend
This way your control doesn't need to know what position to pull data from; it simply knows it's an "Open" so it's text is langDictionary. Value("Open"). Simple to implement and maintain. Tim
Tim,Thanks as I was talking about dictionary sorry for the mix up. So you are saying that do not worry about the control itself but what the control text/caption(normal default text/caption) is as it will then select the correct translation. Ok as that will work for buttons and statictext labels but what about the statictext that is used for informaton?statictext1 text = "Please enter your First and Last Name before saving the file."How would you do that as with reference to your Open example?
Tim,Thanks for clearing that up. Also is there any way of making a small demo example so I can see how all this will work. I have one client that is bugging me for a Spanish edition but I don't speak Spanish and if I did I wanted to do a on-the-fly language selection. He said he help with the translation but I have been putting him off as I was not ready. With this new information I think I can do it. Oh his wife does not undersand english so that is why he wants a spanish edition for her as shes the one with the health problems.
Is there a way to tell the App to run in a different language other than the default?I have a plugin for Mac that allows me to tell an App to start up in a different language. Is there a way to do that using RB code and for Windows and MacI want to use Lingua to Localize. I want to have an "Options Windows" to allow the user to change the Language. This way all the language resources are external and the user can remove the one that are not used to save space.
Forex Groups - Tips on Trading
Related article:
http://forums.realsoftware.com/viewtopic.php?p=98058#98058
comments | Add comment | Report as Spam
|