MvvmCross本地化:在运行时切换 [英] MvvmCross localization: switch at runtime

查看:88
本文介绍了MvvmCross本地化:在运行时切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在运行时将当前语言更改为另一种语言?

Is there a way to change the current language to another one at runtime ?

例如:能够在单击按钮或启动应用程序时进行切换,获取用户语言并进行切换.

For example: be able to switch when a button is clicked or when starting the app, get the user language and switch.

如何在启动时告诉插件检查用户语言?

How to tell the plugin to check the user language at startup ?

预先感谢您的帮助.

推荐答案

是否可以在运行时将当前语言更改为另一种语言?

Is there a way to change the current language to another one at runtime ?

是,在您的builder.LoadResources(whichLanguage) rel ="nofollow noreferrer"> MvxTextProviderBuilder.cs

yes, call builder.LoadResources(whichLanguage) on your MvxTextProviderBuilder.cs

例如:能够在单击按钮时进行切换

For example: be able to switch when a button is clicked

实际上没有设置UI框架来实时执行切换.当您在语言之间切换时,新的JSON资源文件将全部加载正常-但现有的显示文本不会更新.这有点像大多数移动操作系统-如果要切换语言,通常需要重新启动!

The UI framework isn't really setup to perform switching live. When you switch between languages then the new JSON resource files will all be loaded OK - but existing displayed text will not be updated. This is a bit like most mobile operating systems - if you want to switch language you often need to reboot!

如果要添加动态切换,则必须找到一种方法来告诉UI完全刷新所有文本-我怀疑这样做并不难,但是可能需要在每个页面上进行一些手动编码/view已经创建并显示:/

If you wanted to add dynamic switching then you'd have to find a way to tell the UI to completely refresh all text - I suspect this wouldn't be hard to do, but it might require some manual coding on every page/View which has already been created and displayed :/

或启动应用程序时,获取用户语言并进行切换.

or when starting the app, get the user language and switch.

这是执行i18n的更直接的方法.通常可以,因为MvvmCross主要针对手机-手机通常是单用户设备,不会经常切换语言.

This is a much more straight-forward way to do i18n. It's normally OK because MvvmCross mainly targets phones - and phones are normally single user devices which don't switch languages very often.

  • 例如,您可以使用一些变量(例如System.Globalization.CultureInfo.CurrentUICulture)来确定显示的最佳语言.

  • You could, for example, use some variable (e.g. System.Globalization.CultureInfo.CurrentUICulture) to work out the best language to display.

或者您在加载时检测用户是否选择了一种语言-如果有,则显示HomeViewModel-如果他们没有然后显示LanguagePickerViewModel-这是我们在StarWarsKinect中所做的- StartNavigationObject是执行此类逻辑的理想场所!

Or you detect on load whether the user has picked a language yet - if they have, then show HomeViewModel - if they haven't then show a LanguagePickerViewModel - this is what we did in StarWarsKinect - the StartNavigationObject is a perfect place for this sort of logic!

如何在启动时告诉插件检查用户语言?

How to tell the plugin to check the user language at startup ?

当前,您必须在应用启动时对此逻辑进行编码.

Currently, you'll have to code this logic as part of your app startup.

我绝对愿意为此提供改进的插件-也许带有演示!

I'd definitely be open to providing an improved plugin on this - perhaps with a demo!

如果您正在查看i18n,那么可以考虑采用另一种实现方式是Vernacular-Rdio的团队为Mono和MS平台提供了非常好的产品-

If you are looking at i18n, then one alternative implementation to consider is Vernacular - the team at Rdio have a very good offering for Mono and MS platforms - https://github.com/rdio/vernacular

这篇关于MvvmCross本地化:在运行时切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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