Lasse Madsen
Lasse Madsen

Reputation: 602

Xamarin.Forms localization on the fly

Is it possible to download and use language files (.resx) on the fly, so I do not have to do a new release, when a new language become available?

Upvotes: 0

Views: 368

Answers (1)

Daniel
Daniel

Reputation: 9521

What you can do is to serialize your translations in a json format so that you just have to update this file.

You create a class that contains your translation.

public class LanguagePack
{
    [JsonProperty(PropertyName = ="LPT")]
    public string LoginPageTitle{get;set;}

    public static LanguagePack Current {get; set;}
}

In your xaml, you can do this

<Label Text="{x:static LanguagePack.Current.LoginPageTitle}"/>

When you get your translation from your server, you can do this (maybe store it somewhere first)

LanguagePack.Current = JsonConvert.Deserialize(yourJsonFile);

Upvotes: 3

Related Questions