1 つのリソース ファイル (ApplicationStrings.fr-CA.resx) を含む、リソース アセンブリが埋め込まれた XAP ファイルを動的にダウンロードしています。この投稿で Jeff Prosise が行った作業に基づいて、WebClient を使用して XAP ファイルをプルダウンし、次のコードを使用してアセンブリをロードしてい ます。 /06/21/dynamic-localization-in-silverlight.aspx .
また、アセンブリと ApplicationManifest.xaml を使用して fr-CA フォルダーから XAP ファイルを手動で作成することに注意してください。 10/Building-Localized-XAP-Resource-Files-For-Silverlight-4.aspx .
// Get the application manifest from the downloaded XAP
StreamResourceInfo sri = new StreamResourceInfo(e.Result, null);
XmlReader reader = XmlReader.Create(Application.GetResourceStream(sri, new Uri("AppManifest.xaml", UriKind.Relative)).Stream);
AssemblyPartCollection parts = new AssemblyPartCollection();
// Enumerate the assemblies in the downloaded XAP
if (reader.Read())
{
reader.ReadStartElement();
if (reader.ReadToNextSibling("Deployment.Parts"))
{
while (reader.ReadToFollowing("AssemblyPart"))
{
parts.Add(new AssemblyPart() { Source = reader.GetAttribute("Source") });
}
}
}
// Load the satellite assemblies
foreach (AssemblyPart part in parts)
{
if (part.Source.ToLower().Contains("resources"))
{
Stream assembly = Application.GetResourceStream(sri, new Uri(part.Source, UriKind.Relative)).Stream;
part.Load(assembly);
}
}
// Change the culture
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
アセンブリは問題なくロードされているようで、名前空間をデフォルトのリソース ファイル (ApplicationStrings.resx) とダウンロードしたリソース ファイル (ApplicationStrings.fr-CA.resx) に一致させました。コードに見られるように、カルチャは現在のスレッドに設定されています。
ただし、ApplicationStrings.ResourceManager.GetString(...) を呼び出しても、設定されたカルチャのリソースは返されません。たとえば、次は新しいカルチャ (fr-CA) の文字列を返す必要がありますが、常に既定のカルチャ (en-US) を返します。
/// <summary>
/// Looks up a localized string similar to User Name:.
/// </summary>
public static string Label_UserName {
get {
return ResourceManager.GetString("Label_UserName", resourceCulture);
}
}
助言がありますか?ありがとう。
* *更新
私はそれを理解しました...サテライトアセンブリプロジェクトファイルでサポートされているローカルをリセットするのを忘れていました:
<SupportedCultures>fr-CA</SupportedCultures>
また、メインの Silverlight アプリケーションの既定のリソースとまったく同じようにフォルダー構造を作成しました。