简体   繁体   English

如何为C#中的本地化创建一个中性的后备卫星资源?

[英]How do I create a neutral fallback satellite resource for localization in C#.?

I am trying to modify an existing WPF application for localization. 我正在尝试修改现有的WPF应用程序以进行本地化。 One of my restrictions is that all resources (including the default en-US fallback resource) have to be satellite resources. 我的限制之一是所有资源(包括默认的美国后备资源)必须是卫星资源。 None of them can be embedded in the main assembly. 它们都不能嵌入到主部件中。

Through some reading on codeplex, I found that all I need to do is make the following change in my AssemblyInfo.cs file. 通过对Codeplex的阅读,我发现我需要做的就是在AssemblyInfo.cs文件中进行以下更改。

[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]

When I do this, I get an exception on application startup saying: 当我这样做时,我在应用程序启动时遇到一个异常:

Could not find any resources appropriate for the specified culture or the neutral culture. 找不到适合于指定区域性或中性区域性的任何资源。 Make sure "XXX.YYY.ZZZ.g.en-US.resources" was correctly embedded or linked into assembly "XXX.YYY.ZZZ" at compile time, or that all the satellite assemblies required are loadable and fully signed. 确保在编译时已将“ XXX.YYY.ZZZ.g.en-US.resources”正确地嵌入或链接到程序集“ XXX.YYY.ZZZ”中,或者确保所需的所有附属程序集均已加载并完全签名。

If I switch back to putting the fallback resource (en-US) in the main assembly, everything works fine again. 如果我转回将后备资源(en-US)放入主程序集中,则一切正常。 From what I've read, if you want to have the fallback resource as a satellite resource, you must have a specific resource for that locale (ie you must have a Resources.en-US.resx). 根据我的阅读,如果您希望将后备资源作为卫星资源,则必须具有针对该语言环境的特定资源(即,必须具有Resources.en-US.resx)。 Am I correct? 我对么?

What seems fishy to me in the exception is the g (.g.en-US). 在我看来,除了g(.g.en-US)之外,我似乎很讨厌。 Does that signify something? 这表示什么吗? The g doesn't exist in any of my resource files? 我的任何资源文件中都不存在g?

Am I creating my resources correctly. 我在正确创建资源吗? I first create a generic Resources.resx file, put all my strings in it. 我首先创建一个通用的Resources.resx文件,并将所有字符串放入其中。 Then, I simply copy/paste within Visual Studio and rename for each specific locale (ar, es-MX, etc.). 然后,我只需在Visual Studio中复制/粘贴并为每个特定的语言环境(ar,es-MX等)重命名。 Then, make the appropriate translations. 然后,进行适当的翻译。

For now, I am just focusing on one projects resource files. 现在,我仅关注一个项目资源文件。 Maybe it's getting hung up on a different project that doesn't have an en-US version of it's resource file?? 也许它挂在另一个没有资源文件的美国版的项目上了? If so, is there any way to get Visual Studio to tell me more about what it's really getting hung up on? 如果是这样,是否有任何方法可以使Visual Studio告诉我有关它真正挂在身上的更多信息?

In short, your understanding of the resource files and what needs built seems correct. 简而言之,您对资源文件和需要构建的内容的理解似乎是正确的。

The .g is for the compiled XAML files and built for you automatically. .g用于已编译的XAML文件,并自动为您构建。 Nothing special or magical going on here. 这里没有什么特别的或不可思议的事情。

Normally the fallback resource is embedded in the main assembly. 通常,后备资源嵌入在主程序集中。 If you are not doing that, you must create a satellite resource assembly for every culture you are going to do, plus an en-US one. 如果您不这样做,则必须为要进行的每种文化创建一个卫星资源程序集,以及一个美国英语版本。

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

相关问题 jQuery将JsonString发布到c#。 我该如何解析 - Jquery Post JsonString to c#. How do I parse it C#。 如何将 String 转换为 Double 数组? - C#. How do i turn a String into a Double array? C#卫星程序集? 我是否需要链接默认的文化资源 - C# Satellite Assemblies? Do I need to link default culture resource 如何使用中性语言资源作为后备? - How to use neutral language resources as fallback? 我想在 C# 中通过授权向 Elasticsearch 发送一个 http 请求(Post、Get 等)。 我怎么做? - I want to send a http request (Post, Get etc) to elasticsearch with authorization in C#. How do I do that? 如何在C#中将ASCII小数转换为字符串。 这是我到目前为止的代码: - How do I convert ASCII decimals to a string in C#. This is the code I have so far: 没有资源文件怎么做本地化? - How to do localization without resource file? C#。 如何完全填充ListView? 所有项目和所有子项目 - C#. How do I fill ListView fully? All Items and all Subitems 无法在Silverlight C#中更改用户代理。 我该怎么办? - Unable to change the user-agent in Silverlight C#. how I can do it? 在 C# 中。 如何使用循环打印用户订单的小计和总计(含税) - In C#. How do I print the subtotal and total(which includes tax) of a user's order using a loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM