Localization for Label StringFormat in Xamarin.Forms
I found the answer at Localizing XAML
I had to add the text The value is: {0} to the resource file.
I needed to add an IMarkupExtension for the translation. I added the class to the same namespace as the resource file.
[ContentProperty("Text")]
public class TranslateExtension : IMarkupExtension
{
private readonly CultureInfo _ci;
static readonly Lazy<ResourceManager> ResMgr = new Lazy<ResourceManager>(
() => new ResourceManager(typeof(AppResources).FullName, typeof(TranslateExtension).GetTypeInfo().Assembly));
public string Text { get; set; }
public TranslateExtension()
{
if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android)
{
_ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo();
}
}
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Text == null)
return string.Empty;
return ResMgr.Value.GetString(Text, _ci) ?? Text;
}
}
and use it like:
<Label Text="{Binding Value, StringFormat={resources:Translate LabelTextTheValueIs}}" />