Set up

There's actually nothing required to set up Localizer. To localize items more comfortably I recommending set Localizer.DefaultResourceManager property when application or website is launching.

Localizer.DefaultResourceManager = new ResourceManager("Application.Resources", this.GetType().Assembly);

Application.Resources defines resource file in format [Project name].[Resource file]. The second parameter specifies assembly for what resource file belongs to. You can access it by this.GetType().Assembly or Assembly.GetExecutingAssembly(). Distinguish language for resource files in .NET is achieved by specifying language code in the file name:

Resources.resx - default resource file (must be always included in VS project
Resources.en.resx - resource file for neutral en culture (English language)
Resources.en-GB.resx - resource file for specific en-GB culture (English language-Great Britain location)

Back to settings. Next what you can set on start up is CultureInfo in Localizer.CurrentCulture. This changes Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture and fires Localizer.CultureChanged event, which you can use to be notified about changing culture in your application through Localizer.

Localizer.CurrentCulture = new CultureInfo("en-GB");
// or
Localizer.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

CreateSpecificCulture is slightly faster. Another set up property is Localizer.ThrowExceptionOnDuplicate. This is useful when you don't want to have duplications of localized property, what can happen in bigger application. Default value is false, but in some cases can be fine to switch on/off this behavior at your pleasure. The last one Localizer.TracingEnabled serves to debug purposes. To trace calling of Localizer methods set this property to true.

Last edited Nov 13, 2011 at 7:45 PM by CSharpDeveloping, version 2

Comments

No comments yet.