Localizable WPF Application - UICulture settings lead to Resource problems

空扰寡人 提交于 2019-12-22 10:33:56

问题


I want to create aa localizable WPF Application. I've followed the instructions in the comments of the AssemblyInfo.cs file:

//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.

After I've done this, my application isn't starting any more. I'm using a custom App class:

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>

Everything has worked fine before. I assume there's some kind of mismatch between the configured UICulture settings and that one specified for MainWindow.xaml, but I don't know how to fix it.


回答1:


I had a similar effect; in the AssemblyInfo.cs, the NeutralResourcesLanguage attribute needed the UltimateResourceFallbackLocation.Satellite parameter:

// 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")]



回答2:


Some background info from: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/wpf-globalization-and-localization-overview

Best Practices for WPF Localization

  • Set the UltimateResourceFallback location in AssemblyInfo.* to specify the appropriate language for fallback (for example, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]).
  • If you decide to include your source language in the main assembly by omitting the <UICulture> tag in your project file, set the UltimateResourceFallback location as the main assembly instead of the satellite (for example, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)])

.



来源:https://stackoverflow.com/questions/6079754/localizable-wpf-application-uiculture-settings-lead-to-resource-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!