Windows Phone 8.1 应用程序 多语言 [英] Windows Phone 8.1 app Multi language

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

问题描述

我正在使用 Visual Studio 2015 在 SilverLight 中创建 Windows 手机应用程序 8.1.我正在创建英语和阿拉伯语的多语言应用程序.为此,我在项目中创建了 Strings 文件夹,其中包含 en-US 和 ar-KW 两个文件夹,每个文件夹中都有 Resources.resw 文件.

I am creating windows phone app 8.1 in SilverLight with Visual Studio 2015. I am creating multi language app in English and Arabic. For that I have created Strings folder in the project with two folder of en-US and ar-KW with Resources.resw file in each folder.

我正在x:Uid 设置属性.例如 Key:- Actual.Text Value:- Actual

I am x:Uid setting properties. For example Key:- Actual.Text Value:- Actual

<TextBlock x:Uid="Actual" TextWrapping="Wrap" MaxWidth="65" HorizontalAlignment="Center" />

以上工作非常好.我有带有 Item EN 和 AR 的组合框.我正在触发 SelectionChanged 事件以更改语言 但问题是当我停止应用程序并再次运行它时,它不仅会更改文本和布局.

Above is working very good. I have combobox with Item EN and AR. I am triggering SelectionChanged event to change the Language But the issue is when I stop the app and run it again than only it change the text and layout.

如何在不重启的情况下在运行时执行此操作.

How can I do it at runtime without restart.

private void LanguageComboBoxName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selectedItem = (e.AddedItems[0] as ComboBoxItem).Content as string;
            var RootFrame = Window.Current.Content as SlideApplicationFrame;

            if (selectedItem == "EN")
                ApplicationLanguages.PrimaryLanguageOverride = "en-US";
            else if (selectedItem == "AR")
                ApplicationLanguages.PrimaryLanguageOverride = "ar-KW";

            RootFrame.Navigate(this.GetType());
    }

推荐答案

据我所知,Microsoft 不建议在运行时更改语言(通过覆盖它),但您可以通过重新加载页面来实现.最简单的方法是将带有代码的组合框放在另一个页面上,在那里您将覆盖语言,因此当您向后导航(并且页面将重新加载)时,您将拥有所需的内容.请记住,覆盖语言不会在运行时本地化控件(但这对您来说应该不是什么大问题).您必须重新启动应用程序才能本地化控件.

As far as i remember it is not recommended by Microsoft to change language in a runtime (by overriding it) but you can do it by reloading the page. The easiest way is to put your combobox with the code on another page and there you will override language, so when you navigate back (and page will be reloaded) you will have what you want. Keep in mind that overriding language will not localize controls in the runtime (but it shouldn't be a great issue for you). You must restart the app to localize controls.

当您使用此代码覆盖语言时:

When you override language with this code:

ApplicationLanguages.PrimaryLanguageOverride = "xx-XX";

然后它被保存,你不必在开始时再次覆盖它.应用将使用覆盖的语言加载.

then it is saved and you don't have to override it again on the start. App will load with the overrided language.

此外,当您本地化应用程序时,最好覆盖文化信息,因为如果您有一些日期 - 它们会针对文化正确显示(例如 12/01/2015 或 01-12-2015)

Additionally when you localize the app it is good to override culture info because if you have some dates - they are shown properly for the culture (e.g. 12/01/2015 or 01-12-2015)

string lang = "en-US";    //default
var culture = new CultureInfo(lang);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = lang;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

还有一件重要的事情.

在您的应用清单或您拥有的内容中,您需要将Generate app bundle 设置为从不".原因是当您将打包版本上传到商店时,您的运行时本地化将不起作用.您可以使用模拟器或调试版本,甚至有时使用已部署的发布版本,在运行时本地化您的应用程序.但是您需要这样做,当您的应用程序在商店中时,本地化就没有问题,并且可以访问所有语言字符串(因为对于打包版本,如果您尚未安装该语言,其中一些可能不会在您的手机上).

In your app manifest or what you have there, you need to set Generate app bundle to "Never". The reason is that when you uploaded packaged version to the store then your runtime localization won't work. You may be able to localize your app in the runtime with emulator or debug versions or even sometimes with deployed release versions. But you need to do that so when your app is in the store then there is no problem with localization and all of the string for languages can be accessed (because for packaged version some of them might not be if you haven't installed the language on your phone).

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

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