我正在關注此guide以本地化我的應用。我不想獲得系統語言,所以我不使用接口和依賴服務ILocalize
。我有英語,西班牙語和法語這3個RESX文件:即時刷新UI語言
- AppResources.es.resx
- AppResources.fr.resx
- AppResources.resx(英文)
這是
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:t="clr-namespace:LanguageTest.Resources;assembly=LanguageTest.Resources"
x:Class="LanguageTest.TestPage">
<Label Text="{t:Translate TestText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
有了這個代碼,我initil:使用TranslateExtension
類從引導我TestPage.xaml
代碼ize語言設置:
public App()
{
// I can change among "en", "es" and "fr"
AppResources.Culture = new CultureInfo("es");
this.MainPage = new NavigationPage(new TestPage());
}
我這種情況下,文本顯示爲西班牙文。但是我想在頁面顯示後更改語言(例如,使用LanguageSettingsPage
用戶可以在應用程序運行時更改語言)。
public App()
{
AppResources.Culture = new CultureInfo("es");
this.MainPage = new NavigationPage(new TestPage());
AppResources.Culture = new CultureInfo("fr");
// At this point the texts are diplayed in Spanish, not in French
}
我怎麼能刷新頁面去不用再次做new TestPage()
顯示法文文本?
你有沒有發現該解決方案?如果是的話,你可以請分享嗎? – batmaci
@batmaci不,我沒找到解決方案。當選擇一種語言時,我將更改App.cs代碼中的所有文本。沒有系統允許你使用綁定或類似的東西來改變文本。 – Jon
重新顯示主頁你可以做'MainPage = new NavigationPage(...);' –