Xamarin.Forms Localization returns always default language -
i trying implement i18n / localization xamarin.forms described here: https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/ - though set language on device french , have resx file french, there's default translation returned. tried deactivating fast deployment (as recommended on forementioned website), no success far.
in line:
var translation = resmgr.value.getstring(text, ci); the value ci fr-ch, returned string default language , not french
// exclude 'extension' suffix when using in xaml markup [contentproperty("text")] public class translateextension : imarkupextension { readonly cultureinfo ci; const string resourceid = "resxi18n.resx.resources"; private static readonly lazy<resourcemanager> resmgr = new lazy<resourcemanager>(() => new resourcemanager(resourceid , typeof(translateextension).gettypeinfo().assembly)); public translateextension() { if (device.os == targetplatform.ios || device.os == targetplatform.android) { ci = dependencyservice.get<ilocalize>().getcurrentcultureinfo(); } } public string text { get; set; } public object providevalue(iserviceprovider serviceprovider) { if (text == null) return ""; var translation = resmgr.value.getstring(text, ci); if (translation == null) { } return translation; } <?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:i18n="clr-namespace:resxi18n.helpers;assembly=resxi18n" xmlns:local="clr-namespace:resxi18n" x:class="resxi18n.resxi18npage"> <label text="{i18n:translate welcome}" verticaloptions="center" horizontaloptions="center" /> the full example can found here: https://github.com/hot33331/resxi18n

Comments
Post a Comment