The internationalization is a big issue for application that will be deployed for different language environment.
Visual Studio 2005 don't integrate the ResGen is very strange thing. We need to do some extra job to integrate the resource file into our program.
So, this article is a document to describe the steps to let a C# application can support multi-language.
Visual Studio 2005 don't integrate the ResGen is very strange thing. We need to do some extra job to integrate the resource file into our program.
So, this article is a document to describe the steps to let a C# application can support multi-language.
- Use notepad create a text file. I named it as i18n.txt with following content
i18nTest.Name = Multi-language testing
i18nTest.Caption = Multi-language caption
i18nTest.bntClickMe = Please push me
i18nTest.Caption = Multi-language caption
i18nTest.bntClickMe = Please push me
- Create a new text file for Tradition Chinese call i18n.zh-tw.txt
i18nTest.Name = 多國語系測試
i18nTest.Caption = 多國語系標題
i18nTest.bntClickMe = 請按我吧
(Be aware save the file with unicode.)
rm = System.Resources.ResourceManager.CreateFileBasedResourceManager("i18n",".",null);
"i18n" is your default language resource file name.
Reference
i18nTest.Caption = 多國語系標題
i18nTest.bntClickMe = 請按我吧
(Be aware save the file with unicode.)
- Using ResGen.exe (should be in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin) compile the text file into resources file.
- Add the files generated by ResGen to project solution.
- Add some code to get the resource string.
- import
- using System.Globalization;
using System.Threading;
using System.Resources; - declare & initialize a resource manager
rm = System.Resources.ResourceManager.CreateFileBasedResourceManager("i18n",".",null);
"i18n" is your default language resource file name.
- switch culture info
- try
{
Thread.CurrentThread.CurrentCulture =
new CultureInfo("zh-TW");
}
catch (Exception ex)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
}
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
- Get resource string
- rm.GetString("i18nTest.Caption");
Reference
- http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx
- http://www.codeproject.com/KB/cs/multilingual_pplication.aspx
沒有留言:
張貼留言