Click here to Skip to main content
15,915,094 members
Home / Discussions / C#
   

C#

 
GeneralRe: Converting a HEX value to a DateTime Pin
Heath Stewart7-Jan-05 5:55
protectorHeath Stewart7-Jan-05 5:55 
QuestionHow to develop multi-language application? Pin
luozhan16-Jan-05 21:10
luozhan16-Jan-05 21:10 
AnswerRe: How to develop multi-language application? Pin
Colin Angus Mackay6-Jan-05 21:39
Colin Angus Mackay6-Jan-05 21:39 
GeneralRe: How to develop multi-language application? Pin
Heath Stewart7-Jan-05 6:21
protectorHeath Stewart7-Jan-05 6:21 
AnswerRe: How to develop multi-language application? Pin
Adam Goossens6-Jan-05 23:45
Adam Goossens6-Jan-05 23:45 
AnswerRe: How to develop multi-language application? Pin
OmegaSupreme7-Jan-05 0:05
OmegaSupreme7-Jan-05 0:05 
GeneralRe: How to develop multi-language application? Pin
Heath Stewart7-Jan-05 5:56
protectorHeath Stewart7-Jan-05 5:56 
AnswerRe: How to develop multi-language application? Pin
Heath Stewart7-Jan-05 6:12
protectorHeath Stewart7-Jan-05 6:12 
You should start by reading Developing World-Ready Applications[^] in the .NET Framework SDK.

Basically, in whatever language you develop your application, that text (and other objects which have an associated TypeConverter) is your neutral resource language and is compiled into your primary assembly (the assembly that contains the IL modules compiled from your code. Any other languages you develop are put into satellite assemblies.

If you're using VS.NET this is very easy (but, until "Whidbey", pretty inefficient at runtime for larger applications). Develop your forms and controls, then select the top-level control (like the Form or UserControl) and find the Localized property (this is actually a design-time property; it is not defined on the class). Set that to true then find the Language property (again, a design-time property). Set that to something else and change the text, positions and sizes of controls, etc.

If you want to see what VS.NET is doing behind the scenes, click Project->Show hidden files from the menu. You'll see a lot of .ResX files nested underneat your control class files. The neutral resource .ResX will not have an ISO lang/locale identifier (like MyClass.resx) while the others will (like MyClass.de-DE.resx or MyClass.es.resx, which are resource files for Germany (German language) and the Spanish language (no locale), respectively.

When you compile your application, satellite assemblies are created. If you then look into your source code, expand the hidden regions and you'll see lots of calls to ResourceManager.GetString or ResourceManager.GetObject (actually, an instance of ResourceManager typically named resources).

When the CultureInfo.CurrentUICulture (not CurrentCulture, which is used for formatting dates, times, and numbers - it specifies the locale, not the language) is set the ResourceManager will try to find a language for that. If any locale is specified in that CultureInfo instance, that locale will be used if it exists. If not the fallback is the language. If a satellite assembly doesn't exist for that, the neutral resources - those inside your primary assembly - are used.

To make this faster, in your AssemblyInfo.cs file (actually, wherever is fine) define the assembly-level attribute NeutralResourcesLanguage set to the "lang-locale" for the language in which your project is developed, like "en-US" for US English. If the ResourceManager needs to find those reosurces, it will not not to go probing for them (which is especially slow if deploying your managed application using touchless deployment across the Internet or even an intranet).

Be sure to read that link I gave you, as well as some of the classes you'll be using like ResourceManager and CultureInfo. Taking a look at what VS.NET does (because that's about what you'd do if you did it manually) is also extremely helpful.

If you use VS.NET to do this your clients can even localize your application without the source using winres.exe from the .NET Framework SDK, or a separate localization team if you have such an entity. You can use this if you do it manually, but you must understand what is required that winres.exe looks for, which you can learn by looking to see what VS.NET does.

Here's the catch: VS.NET declares instantiates the ResourceManager in InitializeComponents. If you want to support switching languages in the middle of the application (which you can do by setting CultureInfo.CurrentUICulture, then you'll need to re-initialize - not re-instantiate - your controls. To do this efficiently you'll need to break VS.NET's design-time support by abstracting the initialization out of InitializeComponents, leaving only the instantiation in there (or more the instantiation to another method). This means you can call a method to re-initialize the controls (how you trigger this is up to you). This is pretty uncommon for larger projects, as many problems can occur and since most people don't need to switch languages in the middle of a Windows session.

Note, too, that MUI (multi-user interfaces API) automatically sets CultureInfo.CurrentUICulture (actually, the property is initialized from the current MUI language). So, if a user is using a German Windows installation or the German MUI as I sometimes do, CultureInfo.CurrentUICulture would automatically be set to "de-DE" so your application - if localized for "de-DE" or just "de" - would automatically display your German text and control positions, sizes, etc.

If you'd like more information about how "Whidbey" is improving efficency while using the designer to localize applications, read my blog entry at http://blogs.msdn.com/heaths/archive/2004/10/05/237987.aspx[^].

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]

QuestionHow to make nice GUI like this? Pin
luozhan16-Jan-05 20:59
luozhan16-Jan-05 20:59 
AnswerRe: How to make nice GUI like this? Pin
perlmunger7-Jan-05 5:29
perlmunger7-Jan-05 5:29 
QuestionProblem calling dll from asp.net - workaround? Pin
totig6-Jan-05 20:32
totig6-Jan-05 20:32 
AnswerRe: Problem calling dll from asp.net - workaround? Pin
OmegaSupreme7-Jan-05 0:12
OmegaSupreme7-Jan-05 0:12 
GeneralRe: Problem calling dll from asp.net - workaround? Pin
totig7-Jan-05 0:41
totig7-Jan-05 0:41 
GeneralRe: Problem calling dll from asp.net - workaround? Pin
OmegaSupreme7-Jan-05 1:05
OmegaSupreme7-Jan-05 1:05 
GeneralInsert a line into the begining of the text file Pin
itssuk6-Jan-05 19:49
itssuk6-Jan-05 19:49 
GeneralRe: Insert a line into the begining of the text file Pin
Yulianto.6-Jan-05 21:22
Yulianto.6-Jan-05 21:22 
GeneralRe: Insert a line into the begining of the text file Pin
itssuk6-Jan-05 22:57
itssuk6-Jan-05 22:57 
GeneralRe: Insert a line into the begining of the text file Pin
Adam Goossens7-Jan-05 0:02
Adam Goossens7-Jan-05 0:02 
GeneralRe: Insert a line into the begining of the text file Pin
Stefan Troschuetz7-Jan-05 0:10
Stefan Troschuetz7-Jan-05 0:10 
GeneralRe: Insert a line into the begining of the text file Pin
Dave Kreskowiak7-Jan-05 3:10
mveDave Kreskowiak7-Jan-05 3:10 
GeneralBest way to accomplish... Pin
Matt Newman6-Jan-05 15:03
Matt Newman6-Jan-05 15:03 
GeneralRe: Best way to accomplish... Pin
Christian Graus6-Jan-05 15:09
protectorChristian Graus6-Jan-05 15:09 
GeneralRe: Best way to accomplish... Pin
Matt Newman6-Jan-05 15:12
Matt Newman6-Jan-05 15:12 
GeneralRe: Best way to accomplish... Pin
Christian Graus6-Jan-05 21:14
protectorChristian Graus6-Jan-05 21:14 
GeneralRe: Best way to accomplish... Pin
Vega026-Jan-05 15:33
Vega026-Jan-05 15:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.