本地化 Windows Phone 7 应用程序 [英] Localizing Windows Phone 7 App

查看:31
本文介绍了本地化 Windows Phone 7 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取本地化资源文件以在 Windows Phone 7 上运行时遇到了一些麻烦.这是我正在做的事情:

I'm having a little trouble getting localized resources files to work on Windows Phone 7. Here's what I'm doing:

  1. 创建一个资源文件,比如Strings.resx"(构建操作:编译)
  2. 创建一个密钥,说TestKey",默认值为空字符串
  3. 在同一个文件夹中添加一个值为一些英文字符串"的英文资源文件:Strings.en-us.resx (Build Action: Embedded Resource)
  4. 在同一个文件夹中添加一个值为some Japanese string"的日语资源文件:Strings.ja-jp.resx(构建操作:嵌入式资源)

在我的 PC Silverlight 中,当我更改 Thread.CurrentThread.CurrentCulture 时,WPF 应用程序运行良好.但在电话中,我似乎总是得到 Strings.resx 文件中的值 - 一个空字符串.

In my PC Silverlight, WPF Apps that works fine when I change the Thread.CurrentThread.CurrentCulture. But in the phone I always seem to be getting the value that's in the Strings.resx file - an empty string.

我曾尝试使用设计器生成的代码并手动连接资源管理器,但似乎无关紧要.这是我的代码:

I have tried using the designer generated code and wiring up the resource manager by hand and it does not seem to matter. Here's my code:

            Type t = typeof(Strings);

            _resourceManager = new ResourceManager(
                t.Namespace + "." + t.Name,
                t.Assembly);

            _resourceManager.GetString("TestKey");

告诉我手机支持本地化资源... ;> 我做错了什么?谢谢!

Tell me localized resources are supported on the phone... ;> What am I doing wrong? Thanks!

更新:感谢 Olivier 转发链接.我也看到了,但错过了重要的一步.我没有将SupportedCultures"节点添加到我的 csproj.完全不同 - 希望其他人不会像我一样浪费两个小时试图解决这个问题.

Update: Thanks Olivier for forwarding the link. I saw that as well but missed an important step. I didn't add the "SupportedCultures" node to my csproj. Made all the difference - hoping someone else doesn't loose two hours trying to figure this out like I did.

<SupportedCultures>de-DE;es-ES;</SupportedCultures>

推荐答案

我写了一篇博客文章,提供了指向一堆 WP7 的全球化/本地化指南. 有一个 Windows Phone 7 in 7 培训视频,帮助我了解基础知识.之后就只需要学习如何进行数据绑定了:

I wrote a blog post that provides links to a bunch of Globalization / Localization guides for WP7. There is a Windows Phone 7 in 7 Training video that helped me understand the basics. After that it was simply a matter of learning how to do databinding:

MSDN 文章向您展示了如何设置文件并创建LocalizedStrings 类,但它们随后假设你知道如何使用它数据绑定类.视觉工作室2010 和 Silverlight 处理数据绑定与 Winform 不同,并且自从 XAML 以来它变得更加混乱也有自己的定义不同的资源我们刚刚创建的 .NET 资源.Silverlight 也使用术语引用文件的资源内容"的构建动作,如这些文件被包裹到.XAP 文件类似于 how files with资源"的构建动作获取嵌入到 .dll 程序集中(例如:从内容加载图像或资源文件).我发现相反使用 Text="{Binding路径=resourceFile.resourceName,源={静态资源Localizedresources }}" XAML 语法它使用以下步骤更容易:

The MSDN article shows you how to setup the files and create the LocalizedStrings class, but they then assume that you know how to use that class for data binding. Visual Studio 2010 and Silverlight handle data binding differently than Winforms, and it gets even more confusing since XAML also has it’s own definition of Resources that are different then the .NET resources we just created. Silverlight also uses the term Resource to refer to files that use the the Build Action of "Content", as these files get wrapped up into the .XAP file similar to how files with Build Action of "Resource" get embedded into the .Dll assembly (ex: loading an image from content or resource files). I found that instead of using the Text="{Binding Path=resourceFile.resourceName, Source={StaticResource Localizedresources }}" XAML syntax it was easier to use the following steps:

  1. 在 Visual 中打开您的主要 XAML 页面(通常是 MainPage.xaml)工作室设计师

  1. Open your primary XAML page (usually MainPage.xaml) in the Visual Studio designer

打开 PhoneApplicationPage 的属性并设置数据上下文Application.Resources –>本地化字符串.注意:如果你已经正在使用 DataContext 对象,然后你应该整合LocalizedStrings 类对象,以便它具有本地化支持.

Open the properties for the PhoneApplicationPage and set the DataContext to be Application.Resources –> LocalizedStrings. NOTE: if you already are using a DataContext object, then you should integrate the LocalizedStrings class into that object so that it has localization support.

一旦设置了页面的数据上下文,您就可以更改数据绑定页面上的任何控件只需选择属性(例如:文本、选中等),选择应用数据绑定...",并设置路径到 Localizedresources.BtnText 或无论想要的名字是什么资源价值是.

Once the Page’s DataContext has been set you can change the data binding for any control on the page by simply selecting the property (ex: text, checked, etc), selecting "Apply Data Binding…", and setting the Path to Localizedresources.BtnText or whatever the name of the desired resource value is.

这篇关于本地化 Windows Phone 7 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆