我想创建一个可本地化的WPF应用程序。我已经按照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.

完成此操作后,我的应用程序不再启动。我正在使用自定义应用程序类:

namespace Namespace
{
    public partial class App : Application
    {
        [STAThread()]
        [SecurityPermission(SecurityAction.LinkDemand)]
        public static void Main()
        {
            var app = new App();

            app.InitializeComponent();
            app.Run();
        }


        [DebuggerNonUserCode()]
        public void InitializeComponent()
        {
            this.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
        }
    }
}

 

<ns:App
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ns="clr-namespace:Namespace">

</ns:App>

以前一切都很好。我假设配置的UICulture设置和为MainWindow指定的设置之间存在某种不匹配。xaml,但不知道如何修复它。

有帮助吗?

解决方案

我有类似的效果;在ObjecuponalInfo.cs中,NeutralResourcesLanguage属性需要UltimateResourceFallbackLocation.Satellite参数:

// Uncommenting the following line --> OK
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
// Uncommenting the following line --> IOException: Cannot locate resource 'app.xaml'.
// [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
// Uncommenting the following line --> IOException: Cannot locate resource 'app.xaml'.
// [assembly: NeutralResourcesLanguage("en-US")]
.

其他提示

一些背景资料: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/wpf-globalization-and-localization-overview

WPF本地化的最佳实践

  • 设置 UltimateResourceFallback AssemblyInfo中的位置。*至 为回退指定适当的语言(例如, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]).
  • 如果您决定将源语言包含在主程序集中,请通过 省略 <UICulture> 在项目文件中标记,设置 UltimateResourceFallback 作为主组件的位置,而不是 卫星(例如, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)])

.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top