我只是不能让本地化工作。
我有一个类库。现在我想在那里创建resx文件,并根据线程区域性返回一些值。
我该怎么做呢?
我只是不能让本地化工作。
我有一个类库。现在我想在那里创建resx文件,并根据线程区域性返回一些值。
我该怎么做呢?
当前回答
通常你把翻译放在资源文件中,例如resources.resx。
每个特定区域性都有不同的名称,例如resources.nl。Resx, resources.fr.resx, resources.de.resx,…
现在解决方案中最重要的部分是维护您的翻译。 在Visual Studio中安装Microsoft MAT工具:多语言应用程序工具包(MAT)。 工作与winforms, wpf, asp.net(核心),uwp,…
一般来说,例如对于WPF解决方案,在WPF项目中
Install the Microsoft MAT extension for Visual Studio. In the Solution Explorer, navigate to your Project > Properties > AssemblyInfo.cs Add in AssemblyInfo.cs your default, neutral language (in my case English): [assembly: System.Resources.NeutralResourcesLanguage("en")] Select your project in Solution Explorer and in Visual Studio, from the top menu, click "Tools" > "Multilingual App Toolkit" > "Enable Selection", to enable MAT for the project. Now Right mouse click on the project in Solution Explorer, select "Multilingual App Toolkit" > "Add translation languages…" and select the language that you want to add translations for. e.g. Dutch.
您将看到将创建一个名为“MultilingualResources”的新文件夹,其中包含一个....nl。xlf文件。
你现在要做的唯一一件事是:
将翻译添加到默认资源中。resx文件(在我的例子中是英文) 通过点击.xlf文件(不是.resx文件)进行翻译,因为.xlf文件将生成/更新.resx文件。
(.xlf文件应该用“多语言编辑器”打开,如果不是这样,鼠标右键单击。xlf文件,选择“用…打开”,然后选择“多语言编辑器”。
玩得开心!现在你还可以看到没有翻译的内容,用XLF导出翻译到外部翻译公司,再次导入,从其他项目回收翻译等等……
更多信息:
使用多语言App Toolkit 4.0: https://learn.microsoft.com/windows/uwp/design/globalizing/use-mat 多语言App Toolkit博客,请访问: http://aka.ms/matblog 多语言App Toolkit用户语音功能投票网站,访问: http://aka.ms/matvoice
其他回答
除了@Eric Bole-Feysot的回答:
由于卫星程序集,本地化可以基于.dll/.exe文件创建。这种方式:
源代码(VS项目)可以与语言项目分离, 添加新语言不需要重新编译项目, 甚至最终用户也可以进行翻译。
有一个鲜为人知的工具叫做LSACreator(非商业用途免费或购买选项),它允许您基于.dll/.exe文件创建本地化。事实上,它在内部(在语言项目的目录中)创建/管理resx文件的本地化版本,并以类似于@Eric Bole-Feysot所描述的方式编译程序集。
此外,@Fredrik Mörk关于字符串的伟大回答,要添加本地化到一个表单,请执行以下操作:
将表单的属性“Localizable”设置为true 将表单的Language属性更改为您想要的语言(从一个漂亮的下拉菜单中) 翻译这种形式的控件,并在需要时移动它们(把那些非常长的完整的法语句子塞进去!)
编辑:这篇MSDN关于Windows窗体本地化的文章不是我链接的原始文章…但如果需要的话,可能会提供更多线索。(旧的已经被拿走了)
你可以使用Lexical。本地化¹允许将默认值和区域性特定值嵌入到代码中,并在外部本地化文件中扩展为进一步的区域性(如.json或.resx)。
public class MyClass
{
/// <summary>
/// Localization root for this class.
/// </summary>
static ILine localization = LineRoot.Global.Type<MyClass>();
/// <summary>
/// Localization key "Ok" with a default string, and couple of inlined strings for two cultures.
/// </summary>
static ILine ok = localization.Key("Success")
.Text("Success")
.fi("Onnistui")
.sv("Det funkar");
/// <summary>
/// Localization key "Error" with a default string, and couple of inlined ones for two cultures.
/// </summary>
static ILine error = localization.Key("Error")
.Format("Error (Code=0x{0:X8})")
.fi("Virhe (Koodi=0x{0:X8})")
.sv("Sönder (Kod=0x{0:X8})");
public void DoOk()
{
Console.WriteLine( ok );
}
public void DoError()
{
Console.WriteLine( error.Value(0x100) );
}
}
对我来说
[assembly: System.Resources.NeutralResourcesLanguage("ru-RU")]
在AssemblyInfo.cs中阻止事情正常工作。
通常你把翻译放在资源文件中,例如resources.resx。
每个特定区域性都有不同的名称,例如resources.nl。Resx, resources.fr.resx, resources.de.resx,…
现在解决方案中最重要的部分是维护您的翻译。 在Visual Studio中安装Microsoft MAT工具:多语言应用程序工具包(MAT)。 工作与winforms, wpf, asp.net(核心),uwp,…
一般来说,例如对于WPF解决方案,在WPF项目中
Install the Microsoft MAT extension for Visual Studio. In the Solution Explorer, navigate to your Project > Properties > AssemblyInfo.cs Add in AssemblyInfo.cs your default, neutral language (in my case English): [assembly: System.Resources.NeutralResourcesLanguage("en")] Select your project in Solution Explorer and in Visual Studio, from the top menu, click "Tools" > "Multilingual App Toolkit" > "Enable Selection", to enable MAT for the project. Now Right mouse click on the project in Solution Explorer, select "Multilingual App Toolkit" > "Add translation languages…" and select the language that you want to add translations for. e.g. Dutch.
您将看到将创建一个名为“MultilingualResources”的新文件夹,其中包含一个....nl。xlf文件。
你现在要做的唯一一件事是:
将翻译添加到默认资源中。resx文件(在我的例子中是英文) 通过点击.xlf文件(不是.resx文件)进行翻译,因为.xlf文件将生成/更新.resx文件。
(.xlf文件应该用“多语言编辑器”打开,如果不是这样,鼠标右键单击。xlf文件,选择“用…打开”,然后选择“多语言编辑器”。
玩得开心!现在你还可以看到没有翻译的内容,用XLF导出翻译到外部翻译公司,再次导入,从其他项目回收翻译等等……
更多信息:
使用多语言App Toolkit 4.0: https://learn.microsoft.com/windows/uwp/design/globalizing/use-mat 多语言App Toolkit博客,请访问: http://aka.ms/matblog 多语言App Toolkit用户语音功能投票网站,访问: http://aka.ms/matvoice