Dynamic Localization

I am creating an application which will be released in several countries.

I know about using resource files to allow the correct language to appear in all messages/ captions etc, however, I would like to be able to change the language dynamicly.

Example: A User in the US (For whatever reasons) suddenly wants to view the application in French. Selecting the appropriate menu item or button should change everything to French without the need to close the application first.

I am a little lost on this one.

Any help would be very greaty appreciated.

CTD
ctdevAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KDivadCommented:
I "grew up" with QB, so I always put all the strings into constants and load the appropriate one when I need it.

Global Const Bye_Eng = "GoodBye!"
Global Const Bye_Itl = "Ciao!"

Or something like that.
0
watyCommented:
I use the following code :

You add to all your text a unique ID like : Form1.Caption = "Main form@4"

You store all the translations in a ressource string, and for example,
English gnLangue = 0
Frensh  gnLangue = 1000

Using the code below will be very easy

NB : I am working on an application wich will do translation of VB projects in several other languages



' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : http://www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 08/11/1999
' * Time             : 12:30
' **********************************************************************
' * Comments         : Translate string from resource string
' *
' *
' **********************************************************************
Global gnLangue            As Long

Public Sub TraductForm(TheForm As Form)
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 08/11/1999
   ' * Time             : 12:07
   ' * Module Name      : TRADUCT
   ' * Module Filename  : TRADUCT.BAS
   ' * Procedure Name   : TraductForm
   ' * Parameters       :
   ' *                    TheForm As Form
   ' **********************************************************************
   ' * Comments         : Traduct all the controls on a form
   ' * We use the ID after the @ ***
   ' *
   ' **********************************************************************

   ' #VBIDEUtilsERROR#
   On Error GoTo ERROR_TraductForm

   Dim nI               As Integer
   
   ' *** Translate the caption of the form
   TheForm.Caption = Traduction(CStr(TheForm.Caption))
   
   For nI = 0 To TheForm.Controls.Count - 1
      ' *** Translate all the captions
   
      If TypeOf TheForm.Controls(nI) Is Label Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is Menu Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is CommandButton Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is SSCommand Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is SSFrame Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is SSPanel Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is SSOption Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      ElseIf TypeOf TheForm.Controls(nI) Is SSCheck Then
         TheForm.Controls(nI).Caption = Traduction(CStr(TheForm.Controls(nI).Caption))
      End If
   Next
   

EXIT_TraductForm:
   Exit Sub

   ' #VBIDEUtilsERROR#
ERROR_TraductForm:
   
   Resume EXIT_TraductForm
   
End Sub

Public Function Traduction(sText As String) As String
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 08/11/1999
   ' * Time             : 12:07
   ' * Module Name      : TRADUCT
   ' * Module Filename  : TRADUCT.BAS
   ' * Procedure Name   : Traduction
   ' * Parameters       :
   ' *                    sText As String
   ' **********************************************************************
   ' * Comments         :
   ' * Translate a text using the ID in the string after the @
   ' *
   ' **********************************************************************

   ' #VBIDEUtilsERROR#
   On Error GoTo ERROR_Traduction

   Dim sTmp             As String
   Dim sID              As String
   Dim nPos             As Integer
   Dim nReturn          As Integer

   Traduction = sText

   sTmp = ""

   ' *** Search the @
   nPos = InStr(sText, "@")
   
   ' *** No traduction found
   If (nPos = 0) Then
      Traduction = sText
      Resume EXIT_Traduction
   End If

   sID = Right(sText, Len(sText) - (nPos))
   
   ' *** No identifiant found
   If (IsNumeric(sID) = False) Then
      Traduction = Left(sText, nPos - 1)
      Resume EXIT_Traduction
   End If

   sTmp = Trim(LoadResString(gnLangue + CLng(sID)))
   
   ' *** No traduction found
   If (sTmp = "") Then
      Traduction = Left(sText, nPos - 1)
      Resume EXIT_Traduction
   End If

   Traduction = sTmp

EXIT_Traduction:
   Resume EXIT_Traduction

   ' #VBIDEUtilsERROR#
ERROR_Traduction:
   
   Resume EXIT_Traduction

End Function

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AnswerTheManCommented:
if your app will need to run in HEBREW or ARABIC - all those solutions will not work.
those languages are written from RIGHT to LEFT.
that meand that all controls aligen and RTL properties will have to be changed, the controls locations will have to be changed in order to be alighed diffrently on the forms, the user input should be diffrent. even MsgBox's text align is diffrent.
in addition - you'll need each language specific fonts on your development machine to write the strings in that font....
i've been there.....
you'll need to make a total diffrent version for those RTL languages.

and - your installation will have to install a specipic MS DLL (vbame.dll) to make all this possible...


0
ctdevAuthor Commented:
Waty:
Many thanks for the code, however, I am not sure I understand how it will work. Do you mean that all of the strings will be in a single resource file?

Any extra explanation would be appreciated at this point!

Thanks agagin...

CTD
0
watyCommented:
In fact, you have all the string in your project, all those strings have a unique identifiant after this string.

In the form_load, you call the the traduct_form wich get all the ID and take the translation in the resource file (or a DB if you modify the code for this) and modify the string.

If no translation is found, it leaves the string found
0
watyCommented:
In fact, you have all the string in your project, all those strings have a unique identifiant after this string.

In the form_load, you call the the traduct_form wich get all the ID and take the translation in the resource file (or a DB if you modify the code for this) and modify the string.

If no translation is found, it leaves the string found
0
ctdevAuthor Commented:
Aha!

Now I get it! (I Think!)

Many thanks Waty. I think I should be able to sort this out myself now.

Excellent job, thanks again... CTD
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.