0

私はiOS用のPCLプロジェクトがあり、Windows Phone 8.1バージョンを作成しようとしています。 https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/Xamarin PCLソリューションにresxローカリゼーションを使用してWindows Phoneプロジェクトを追加するにはどうすればよいですか?

をとATのアプリをチェック:

私はこのチュートリアルを以下のよhttps://github.com/xamarin/xamarin-forms-samples/tree/master/UsingResxLocalization

しかし、それはあまりにも推奨されていません。 gitプロジェクトでもチュートリアルとは異なり、どれも動作しません。

Windows用ILocalizeインターフェイスは、次のようになります。単に存在しない

[assembly: Dependency(typeof(UsingResxLocalization.WinPhone.Localize))] 

namespace UsingResxLocalization.WinPhone 
{ 
    public class Localize : UsingResxLocalization.ILocalize 
    { 
     public System.Globalization.CultureInfo GetCurrentCultureInfo() 
     { 
      return System.Threading.Thread.CurrentThread.CurrentUICulture; 
     } 
    } 
} 

しかしSystem.Threading.Thread.CurrentThread.CurrentUICulture。私は代わりにWindows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString()を使うことができることを知りました。

ローカライズされた言語リソースに対しては機能しますが、デフォルトのリソース "en"または "ru"などのローカライズされていない他の言語ではデフォルトのリソースは機能しません。私が取得TranslateExtentionクラスProvideValue()メソッドで

Key 'Start' was not found in resources 'AppNameSpace.AppResources' for culture 'en'

は、「スタート」、それはリソースから取得しようとする最初のキーである私は別のエラーを取得します。これは、プロジェクト上の他のすべてのキーで発生します。

AppNameSpace.AppResourcesは正しいファイル、「en」は設定した領域なので動作するはずです。しかし、そうではありません。

コンパイルするとき、私はまた、次の警告を取得しています:

The assembly "MyApp.dll" does not have a NeutralResourcesLanguageAttribute on it. To be used in an app package, portable libraries must define a NeutralResourcesLanguageAttribute on their main assembly (ie, the one containing code, not a satellite assembly). 4>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1216,5): warning APPX2002: Cannot find the neutral resource language for the resources for portable library 'MyApp'. Verify that the portable library defines a NeutralResourcesLanguageAttribute. The build is continuing assuming the project's default culture of 'en-US' correctly identifies the portable library's neutral resources. 4>MakePRI : warning 0xdef00522: Resources found for language(s) 'de, es, fr, pt' but no resources found for default language(s): 'en-US'. Change the default language or qualify resources with the default language. http://go.microsoft.com/fwlink/?LinkId=231899

しかし、私はそれを修正する方法は考えています。チュートリアルで

それはまた、言う:

Windows Phone projects must be properly configured for localized text to be displayed. Supported languages must be selected in the Project Options and the WMAppManifest.xml files. If these settings are not updated the localized RESX resources will not be loaded.

ファインが、これらのオプションはもう存在しません。少なくともどこにあるべきか。私は自分のプロジェクトでPackage.appxmanifestというファイルを見つけましたが、その地域のオプションはありません。

私はそれを行うための最新の方法で助けが必要です。

おかげ

答えて

0

は、だから私はあなたがいないのWindows PhoneプロジェクトとソリューションへのWindows Phoneプロジェクトを追加するとき、それはそれは必要なすべてを追加しないことが分かりました。

また、チュートリアルでは必要なものはすべて表示されません(大きなニュースはありません)。

私のすべてのプロジェクトが欠落していたのは、私のPCL AssemblyInfo.csファイルに[assembly: NeutralResourcesLanguage("en-US")]でした。

RESXのチュートリアルでは、あなたが使用する必要があることを述べている:

 if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android) 
    { 
      ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo(); 
    } 

TranslateExtention.csファイルでのWindows Phoneはそれを必要としないので。まあ、それは間違いです。少なくともエミュレータが適切な言語を取得するには、DependencyServiceを使用してCultureInfoを次のように取得する必要があります。

System.Globalization.CultureInfo ci = null; 
    ci = new System.Globalization.CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString()); 
    return ci; 
関連する問題