我有这样的程序设置:
逻辑/交互项目具有用于各种不同语言的资源文件(例如'Resources.de.resx','Resources.ja.resx'等...),而示例项目仅具有单个资源文件('Resources .resx')。
示例项目无需修改即可正常运行和启动,但是当我将以下行添加到示例项目中时:
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
我不断收到以下错误:
System.IO.IOException: 'Cannot locate resource '<resource-name>.xaml'
位置根据我将行放入项目的位置而异。
我不太确定更改UI文化的后果,特别是资源文件和本地化的工作方式-因此,有关本地化更改可能导致资源错误的任何指示都将非常有帮助。
NeutralResourcesLanguage
中的AssemblyInfo.cs
设置。打开AssemblyInfo.cs
文件,查找该设置。您通常会看到以下评论://In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
因此,您必须取消注释定义NeutralResourcesLanguage的最新行的注释,并确保该行中的语言代码与您的中性语言完全匹配。因此,例如,如果您在应用程序中选择
第二个参数告诉应用程序在哪里可以找到本地化资源DLL中未包含的资源。两个可用的选项是:"fr"
作为中性语言,则无法在其中设置"fr-FR"
,反之亦然。UltimateResourceFallbackLocation.Satellite:在中性语言资源DLL中查找丢失的资源。如果您选择在资源DLL中使用中性语言(同名,但没有语言标签),则必须选择此选项。这很可能是您需要的选项。
- [UltimateResourceFallbackLocation.MainAssembly:当您没有使用中立语言的附属dll并且所有内容都保留在主程序集中时,需要此选项。
就我而言,我已经包括了该设置,但我犯了两个错误:我将中性语言定义为 es-ES
,但仅在其中设置了es
,而未将后备模式指定为[C0 ],因此我想未定义的默认值是Satellite
。