Multilingual support in C #

I developed a sample software in C # windows Appliation. How to make it multilingual support software.

Example. One of the message fields displays "Welcome to the sample application."

I installed the software in chineses os, but it displays the message in English only.

I am using a "string table" (resource file) for this problem.

In the string table, I need to create an entry for each message in English and Chinese.

its timely process. is there any other way to do this?

+6
c # winforms localization multilingual
source share
4 answers

Create resource files for each language you want to support, mentioned below.

alternative text http://geekswithblogs.net/images/geekswithblogs_net/dotNETPlayground/resx.gif

Depending on the language / current culture of the user, read the values โ€‹โ€‹from the corresponding language resource file and display in the label or in the MessageBox. Here is a sample code:

public static class Translate { public static string GetLanguage() { return HttpContext.Current.Request.UserLanguages[0]; } public static string Message(string key) { ResourceManager resMan = null; if (HttpContext.Current.Cache["resMan" + Global.GetLanguage()] == null) { resMan = Language.GetResourceManager(Global.GetLanguage()); if (resMan != null) HttpContext.Current.Cache["resMan" + Global.GetLanguage()] = resMan; } else resMan = (ResourceManager)HttpContext.Current.Cache["resMan" + Global.GetLanguage()]; if (resMan == null) return key; string originalKey = key; key = Regex.Replace(key, "[ ./]", "_"); try { string value = resMan.GetString(key); if (value != null) return value; return originalKey; } catch (MissingManifestResourceException) { try { return HttpContext.GetGlobalResourceObject("en_au", key).ToString(); } catch (MissingManifestResourceException mmre) { throw new System.IO.FileNotFoundException("Could not locate the en_au.resx resource file. This is the default language pack, and needs to exist within the Resources project.", mmre); } catch (NullReferenceException) { return originalKey; } } catch (NullReferenceException) { return originalKey; } } } 

In an asp.net asn application, you would use it like this:

 <span class="label">User:</span> 

You would now put:

 <span class="label"><%=Translate.Message("User") %>:</span> 
+4
source share

If you intend to use resource files, as Ram suggested, there is a good localization blog entry here: a complete ASP.NET MVC 2 localization guide . (I should have mentioned that this is for Asp.net mvc 2, it may or may not be useful) You still have to spend time creating tables for each language. I have not used any other approach before, I hope you find something useful

+2
source share

You can do this using resource files. You need to create a resource file for each language, and you can use it when starting the application.

0
source share

Resharper 5.0 can significantly improve the time spent on localization. It has functions that make it easy to navigate to a resource, and underlines (if selected) all lines that are localizable, so itโ€™s harder to skip them.

Given that you have a 30-day trial (full version), you can just install it, do your work, and uninstall if you cannot afford it, but I would suggest saving it :-) It's really worth it. / p>

Localization and globalization of software have always been tough and sometimes undesirable tasks for developers. ReSharper 5 greatly simplifies working with resources by providing a complete set of functions for resx files and resource use in C # and VB.NET code, as well as in ASP.NET and XAML markup.
Highlighted functions include moving a string to a resource, finding ways to use resources, and other navigation actions. In combination with refactoring support, checks and corrections, you get a convenient localization environment.

0
source share

All Articles