【问题标题】:Localizable WPF Application - UICulture settings lead to Resource problems可本地化的 WPF 应用程序 - UICulture 设置导致资源问题
【发布时间】:2011-05-21 05:15:54
【问题描述】:

我想创建一个可本地化的 WPF 应用程序。我已按照 AssemblyInfo.cs 文件的 cmets 中的说明进行操作:

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

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

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 指定的设置之间存在某种不匹配,但我不知道如何解决。

【问题讨论】:

    标签: c# wpf visual-studio localization currentuiculture


    【解决方案1】:

    我也有类似的效果;在 AssemblyInfo.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")]
    

    【讨论】:

    • 算上我,部署到两台类似机器中的一台时出现深奥错误,因为其中一台使用不同的操作系统语言。现在一切都很好。
    【解决方案2】:

    一些背景信息来自:https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/wpf-globalization-and-localization-overview

    WPF 本地化的最佳实践

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

    .

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 2015-10-09
      • 2015-02-18
      • 2015-01-28
      • 1970-01-01
      相关资源
      最近更新 更多