Vee*_*eer 11 c# multilingual web-applications c#-4.0
我有一个多语言的Web应用程序.我正在使用资源文件转换所有控件,即标签,下拉列表,文本和消息.
问题:
例如,注册页面有Prefix-Mr,Mrs,Miss等的下拉.这个前缀数据来自一个表,并且是可配置的,即我们有一个相同的配置网页.
还有许多其他可配置的东西和相应的页面.
我的问题是如何将这些数据转换成其他语言,以及如何保存相同的资源文件无法完成.
任何有实际想法的人都可以指导我.
我目前在应用程序中实现多语言支持的方式是通过以下方法。
\n\n尽管添加翻译后的字符串很乏味,但我发现此方法可确保翻译所有需要的部分,同时保持 UI 代码尽可能简单。
使用基类还允许重用可跨所有语言使用的任何方法或属性。
\n\n为了尝试给出一个基本的轮廓,结构会像这样。
\n\n// 基础语言类
\n\npublic abstract class Language\n{\n // Field to identify the language by.\n public string Code {get; private set;}\n\n // Contructor that takes language code as parameter\n public Language(string code)\n {\n Code = code;\n }\n\n // Add the strings you want translating.\n // Making them abstract means classes that inherit from\n // this class must provide their own implementation of these strings.\n public abstract string Hello {get;}\n public abstract string Goodbye {get;}\n}\nRun Code Online (Sandbox Code Playgroud)\n\n// 英语语言课示例
\n\npublic class en_gb : Language\n{\n // Constructor simply provides base class with the language code.\n public en_gb() : base ("en_gb"){}\n\n // By inheriting from Language these properties must be overridden.\n // Visual Studio will add these properties for you, so you simply need to add the return value.\n public override string Hello {get {return "Hello";} }\n public override string Goodbye {get {return "Goodbye";} }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n// 西班牙语课程示例
\n\npublic class es_sp : Language\n{\n // Constructor simply provides base class with the language code.\n public es_sp() : base ("es_sp"){}\n\n // By inheriting from Language these properties must be overridden.\n // Visual Studio will add these properties for you, so you simply need to add the return value.\n public override string Hello {get {return "Hola";} }\n public override string Goodbye {get {return "Adi\xc3\xb3s";} }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n然后你就可以在某个地方拥有一个全局属性。
\n\npublic Language CurrrentLanguage {get; set;}\nRun Code Online (Sandbox Code Playgroud)\n\n然后,所有需要翻译的元素都可以引用 CurrrentLanguage 属性来返回所需的字符串。
\n\nXAML 示例:
\n\n<TextBlock Text="{Binding Source={StaticResource GlobalValues}, Path=CurrrentLanguage.Hello}" />\nRun Code Online (Sandbox Code Playgroud)\n\n代码示例:
\n\nTextbox1.Text = GlobalValues.CurrentLanguage.Hello;\nRun Code Online (Sandbox Code Playgroud)\n