I18n Package - How to save the user selected language?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

I18n Package - How to save the user selected language?

Postby dec » September 9th, 2011, 12:41 pm

Hi to all!

I want to use the amazing I18n Package and not found how to save the user selected language. Suposse you allow the user to select the application language. It's very easy: just let the user to choose a language from a "TCultureBox" and the I18n Package do the rest. But then close the application and, once the application started again, the language can be not the user previosly selected, but the default one instead.

I tried in various ways but the result are not the expected. For example, I tried to save in the Windows registry the "TCultureBox.ItemIndex" property, and then read from the registry and assigning it to the component. This work, but only with the "TCultureBox", in other words, this appear with the user selected language, but the "TLocalizer" apparently dont know about the change on "TCultureBox" and not translate the application accordingly.

I tried to assign "TLocalizer.CultureIndex" with the value of "CultureBox.ItemIndex" just after assigning the "CultureBox.ItemIndex" when the user selected language is read from the registry, but, I get an extrange behaviour: if the "CultureIndex" match the default language no problem is found, but in other case surprisingly my application options form (?) appear (empty and over the main form) and finally I dont get the expected result.

So, anyone can help me with this issue? In few words: How to save the user selected language? Many thanks in advance!

P.S. My project have a main form, an options form and a data module. The options form contain the "TCultureBox" component, and date module contain a shared "TLocalizer" component, used on the main form and the options form too. I use Delphi XE2 Starter Edition on Windows 7 - 32 bits and I18n Package version 1.1 (june 13, 2011).
dec
Senior Member
Senior Member
 
Posts: 53
Joined: July 17th, 2011, 12:33 am

Re: I18n Package - How to save the user selected language?

Postby Kambiz » September 10th, 2011, 3:09 pm

Here are the rules:

  • When getting or setting the UI language manually (without use of appropriate controls), always use the instance of TLocalizer.
  • Index of particular culture, territory, or currency can vary between sessions of the application. Always use the appropriate unique code to identify a culture, territory, or currency.
For example, to save the current language, we need to obtain the currently selected locale:

Code: Select all
var LocaleToSave: String;

if Assigned(Localizer.Culture) then
   LocaleToSave := Localizer.Culture.Locale
else
   LocaleToSave := ''; // No language is selected

and, to restore a saved locale:

Code: Select all
var SavedLocale: String;

Localizer.Culture := CultureOf(SavedLocale);

The i18nEditor uses registry to save/retrieve user selected language. The code can be found at DataModule.pas.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: I18n Package - How to save the user selected language?

Postby dec » September 10th, 2011, 10:47 pm

Hi there,

Sorry for the delay Kambiz. I will try your solution and put here the results. But in any case thanks very much!
dec
Senior Member
Senior Member
 
Posts: 53
Joined: July 17th, 2011, 12:33 am

Re: I18n Package - How to save the user selected language?

Postby dec » September 11th, 2011, 1:43 am

Hi!

Just to say that work like a charm! Thanks Kambiz! :D

P.S. OMG, I found that if save my "I18nModule.Localizer.Culture.Locale" ever get the default one, even if I change the application language. However, if I save my "CultureBox.Localizer.Culture.Locale", everything is Ok, the appropiate language is saved, and then, when retrieved, applied. :?: :-$
dec
Senior Member
Senior Member
 
Posts: 53
Joined: July 17th, 2011, 12:33 am

Re: I18n Package - How to save the user selected language?

Postby Kambiz » September 11th, 2011, 12:03 pm

Thanks for the information. I'll check it out.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: I18n Package - How to save the user selected language?

Postby dec » September 11th, 2011, 2:50 pm

You're welcome!
dec
Senior Member
Senior Member
 
Posts: 53
Joined: July 17th, 2011, 12:33 am


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron