开发者

Problem in Internationalization - English DLL data is always displayed

开发者 https://www.devze.com 2023-01-15 00:57 出处:网络
I have a requirement where my UI should be shown in 5 different languages apart from English. I have created two DLLs

I have a requirement where my UI should be shown in 5 different languages apart from English.

I have created two DLLs

  1. Component.dll
  2. Component.resources.dll

Component.resources.dll contains nothing but all the strings that are shown in the UI and a class

public class PResources
    {
        private static System.Resources.ResourceManager resourceMgr = new System.Resources.ResourceManager(typeof(PEditResources));

        /// <summary>
        /// Get NLS String method string method
        /// </summary>
        /// <param name="identifier"></param>
        /// <returns></returns>
        public static string GetNLSString(string identifier)
        {
            return resourceMgr.GetString(identifier, Thread.CurrentThread.CurrentUICulture);
        }
        /// <summary>
        /// Returns the NLS Resource Mgr.
        /// </summary>
        /// <returns></returns>
        public static System.Resources.ResourceManager GetNLSResourceMgr()
        {
            return resourceMgr;
        }
}

In Component.dll to display the label text I use the following

label1.text = PResources.GetNLSString("IDS_LABEL1");

In English it works fine... But when the language settings is changed to French or any other, the string displayed is still the English text.

Note: The Component.Resources.dll strings are translated in all languages.

When I debugged... I found that the GetNLSString function the Thread.Current.UICulture is French ... but the resourceMgr object is still pointing to the English .dll path and also the Thread.Current.Culture is English!

Is 开发者_JAVA百科there any solution to this ? have I missed anything.


For every culture, you should create a folder (in the folder where the main program is) for every culture you want to support (id = two letter iso code + optional two letter region).

Inside this folder, you place the *.resources.dll, with only the strings/constants for the target culture.

Visual Studio does this automatically for you if you create an example.resx file (for the default culture) and an example.fr.resx file for French, inside the same project.

0

精彩评论

暂无评论...
验证码 换一张
取 消