0

我有一个适用于iOS的PCL项目,我正在尝试创建Windows Phone 8.1版本。如何将带有Resx本地化功能的Windows Phone项目添加到Xamarin PCL解决方案?

我下面这个教程:https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/

而在检查应用程序:https://github.com/xamarin/xamarin-forms-samples/tree/master/UsingResxLocalization

但为时已过时。即使是git项目也不同于教程,并且它们都不起作用。

的ILocalize界面的Windows应该是这样的:

[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手机项目的解决方案,它不添加它需要的一切。

而且教程不显示的一切,是必要的(没有大的消息出现)。

我所有的项目缺少我的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手机并不需要它。那么,这是错误的。至少为了让仿真器获得正确的语言,它需要使用DependencyService并以这种方式获取CultureInfo:

System.Globalization.CultureInfo ci = null; 
    ci = new System.Globalization.CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString()); 
    return ci; 
相关问题