我正在创建我的第一个Xamarin应用程序(首先是针对UWP,然后是Android,最后可能是iOS)。
基本上,该应用程序需要多种语言:英语(默认),法语,西班牙语,俄语和瑞典语。
我正在尝试添加更少的特定于平台的代码,因此没有添加特定代码用于本地化。
我将UseResxLocaliaztion Xamarin GitHub project与Xamarin Localization Documentation一起使用。
基本上,我只是复制并尝试在我的项目资源上使用。但名称空间为UsingResxLocalization.Resx
,我的WhoStart.Resources
为Resources
,文件夹名称为Resx
而不是ResourceManager
。
我更新了Designer.cs
文件的Generator
属性,并尝试使用resx属性进行不同的操作,例如更改CustomToolNamespace
和WhoStart.projitems
,但没有结果。< / p>
我在某些方面手动更改了Designer.cs
文件,因为我的VisualStudio没有缩进文件而无法生成Debug.WriteLine(AppResources.AddButton);
文件。
尝试访问资源时,我遇到了System.Resources.MissingManifestResourceException。
MainPage.xaml.cs中
Designer.cs
System.Resources.MissingManifestResourceException :'找不到 任何适合特定文化或中立的资源 文化。确保“WhoStart.Resources.AppResources.resources”是 在编译时正确嵌入或链接到程序集“WhoStart.UWP” 时间,或所需的所有卫星组件都是可装载的 完全签了。'
Visual Studio
我觉得它可能来自我的环境:
<?xml version="1.0" encoding="utf-8"?>
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AddButton" xml:space="preserve">
<value>Add new item</value>
<comment>this string appears on a button to add a new item to the list</comment>
</data>
</root>
文件AppResources.resx
namespace WhoStart.Resources {
using System.Reflection;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class AppResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal AppResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WhoStart.Resources.AppResources", typeof(AppResources).GetTypeInfo().Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Add new item.
/// </summary>
internal static string AddButton {
get {
return ResourceManager.GetString("AddButton", resourceCulture);
}
}
}
}
MainPage.xaml.cs中
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>2f09a751-1235-4d87-8839-d5828319ad81</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>WhoStart</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)ColorUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ILocalize.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.resx</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.es.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.es.resx</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Resources\AppResources.fr.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.fr.resx</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)TranslateExtension.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.es.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.es.Designer.cs</LastGenOutput>
<CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.fr.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.fr.Designer.cs</LastGenOutput>
<CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Resources\AppResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
<CustomToolNamespace>WhoStart.Resources</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
</Project>
WhoStart.projitems
vol_cube = ["CV" , "cv", "Cube_vol"] # creates the list
while True: # loops until the user gives a correct input
user_input = input('Please enter something: ')
if user_input in vol_cube: # if their input is a value stored in vol_cube
break # breaks the loop