简体   繁体   English

Xamarin.Forms:UWP应用程序的本地化

[英]Xamarin.Forms: Localization of the UWP app

If I run my app on an UWP device I get the following warning in the Output window: 如果我在UWP设备上运行我的应用程序,我会在“ Output窗口中收到以下警告:

MakePRI : warning 0xdef00522: Resources found for language(s) 'en,de' but no resources found for default language(s): 'de-DE,en-US'. MakePRI:警告0xdef00522:为语言'en,de'找到的资源,但找不到默认语言的资源:'de-DE,en-US'。 Change the default language or qualify resources with the default language. 使用默认语言更改默认语言或限定资源。 http://go.microsoft.com/fwlink/?LinkId=231899 http://go.microsoft.com/fwlink/?LinkId=231899

Don't know if this is related, but I also get 不知道这是否相关,但我也知道

1>C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v14.0\\AppxPackage\\Microsoft.AppXPackage.Targets(2459,5): warning : APPX4001: Build property AppxBundlePlatforms is not explicitly set and is calculated based on currently building architecture. 1> C:\\ Program Files(x86)\\ MSBuild \\ Microsoft \\ VisualStudio \\ v14.0 \\ AppxPackage \\ Microsoft.AppXPackage.Targets(2459,5):警告:APPX4001:构建属性AppxBundlePlatforms未明确设置并基于计算目前正在建筑。 Use 'Create App Package' wizard or edit project file to set it. 使用“创建应用程序包”向导或编辑项目文件进行设置。

This page states, that I have language specific resources, which I haven't qualified with the language tag. 这个页面说明我有语言特定的资源,我没有用语言标签限定。 How can I find out, which resources these are? 我怎样才能知道这些资源是哪些资源?

I have images in the Assets folder, but they are language independent ones. 我在Assets文件夹中有图像,但它们与语言无关。 Furthermore, I've set the default language in the Package.appxmanifest to de-DE . 此外,我已将Package.appxmanifest的默认语言设置为de-DE If I search for the language abbrevation from the warning, I can only find a priconfig.xml and AppxManifest.xml , both in the Debug output folder. 如果我从警告中搜索语言缩写,我只能在Debug输出文件夹中找到priconfig.xmlAppxManifest.xml

What should I do to remove this warning? 我该怎么做才能删除此警告?

Edit: 编辑:

The warning seems to disappear if I add a AppResources.en-US.resx file (currently I have en-US set as default language in Package.appxmanifest ). 如果我添加AppResources.en-US.resx文件(目前我已将en-US设置为Package.appxmanifest默认语言),警告似乎消失了。 Additionally, I have a file for AppResources.de.resx and AppResources.resx (should be en ). 另外,我有一个AppResources.de.resxAppResources.resx的文件(应该是en )。 But why does the sample project doesn't need such a file, despite there should be the same settings? 但是为什么示例项目不需要这样的文件,尽管应该有相同的设置? What I'm missing? 我错过了什么?

Just to extend answer from Nico Zhu - MSFT if you are using .Net Standard there is no assemblyInfo.cs file because everything is stored in the csproj file. 只是为了扩展Nico Zhu - MSFT的答案,如果您使用.Net Standard,则没有assemblyInfo.cs文件,因为所有内容都存储在csproj文件中。 So just go to properties of the shared project and change the Project neutral language to whatever your resx default file is. 因此,只需转到共享项目的属性,将Project中性语言更改为resx默认文件。 or you can right click on the project and edit the project and the line below. 或者您可以右键单击项目并编辑项目和下面的行。

For me problem was,after converting from PCL to Net Standard, suddently UWP application wasnt picking the default resource file which was en-US. 对我来说问题是,在从PCL转换为Net Standard之后,突然UWP应用程序没有选择默认资源文件en-US。 I recognized because i was having this setting in assmeblyInfo.cs and since It was removed, it didnt work. 我认识到因为我在assmeblyInfo.cs中有这个设置,因为它被删除了,它没有用。 But somehow it works fine for Android project. 但不知何故,它适用于Android项目。

  <PropertyGroup>
     <NeutralLanguage>en-US</NeutralLanguage>
  </PropertyGroup>

在此输入图像描述

The warning seems to disappear if I add a AppResources.en-US.resx file (currently I have en-US set as default language in Package.appxmanifest). 如果我添加AppResources.en-US.resx文件(目前我已将en-US设置为Package.appxmanifest中的默认语言),警告似乎消失了。 Additionally, I have a file for AppResources.de.resx and AppResources.resx (should be en). 另外,我有一个AppResources.de.resx和AppResources.resx的文件(应该是en)。 But why does the sample project doesn't need such a file, despite there should be the same settings? 但是为什么示例项目不需要这样的文件,尽管应该有相同的设置? What I'm missing? 我错过了什么?

As you said, the AppResources.resx is en. 如你所说, AppResources.resx是en。 And you could expand the Properties node in the Portable Class Library (PCL) project and double-click on the AssemblyInfo.cs file. 您可以展开可移植类库(PCL)项目中的Properties节点,然后双击AssemblyInfo.cs文件。 Add the following line to the file to set the neutral resources assembly language to English: 将以下行添加到文件中以将中性资源汇编语言设置为英语:

[assembly: NeutralResourcesLanguage("en")]

This informs the resource manager of the app's default culture, therefore ensuring that the strings defined in the language neutral RESX file (AppResources.resx) will be displayed when the app is running in one the English locales. 这会通知资源管理器应用程序的默认文化,因此确保当应用程序在英语语言环境中运行时,将显示语言中性RESX文件(AppResources.resx)中定义的字符串。

You have set en-US as default language in Package.appxmanifest , However, there is no such file corresponding to it. 您已在Package.appxmanifest中将en-US设置为默认语言,但是没有与之对应的此类文件。 So it will throw warning. 所以它会发出警告。

The default language of the sample project is en-US , and there is no such file corresponding to it. 示例项目的默认语言是en-US ,并且没有与之对应的此类文件。 It also throw the same warning in my side. 它也向我发出同样的警告。 if you modify the default language to en , the warning disappear. 如果将默认语言修改为en ,警告将消失。 Because it has set AppResources.resx as en in AssemblyInfo.cs file. 因为它已将AppResources.resx设置为AssemblyInfo.cs文件中的en

Foe more you could refer to AssemblyInfo , Supported languages . 你可以参考AssemblyInfo支持的语言

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM