ローカライズ可能な WPF アプリケーション - UICulture 設定によりリソースの問題が発生する
-
08-09-2020 - |
質問
ローカライズ可能な 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.
これを実行すると、アプリケーションは起動しなくなります。カスタム 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 に指定された設定の間に何らかの不一致があると思われますが、それを修正する方法がわかりません。
解決
私は同様の効果を持っていました。AssemballInfo.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")]
. 他のヒント
WPF ローカリゼーションのベスト プラクティス
- をセットする
UltimateResourceFallback
AssemblyInfoの場所。*フォールバックに適した言語を指定するには(たとえば、[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
). - メインアセンブリにソース言語を含めることにした場合
<UICulture>
プロジェクト ファイル内でタグを設定するには、UltimateResourceFallback
衛星の代わりにメインアセンブリとしての場所(たとえば、[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
)
.
所属していません StackOverflow