Skip to content

What is the best way to implement multi-language in XAML app? #16445

Answered by kyuranger
panthernet asked this question in Q&A
Discussion options

You must be logged in to vote

Firsly, I created an extension like this:

  public class LocalizationExtension : MarkupExtension
  {
      public override object ProvideValue(IServiceProvider serviceProvider)
      {
             return LocalizationHelper.GetLocalizedString(_Key);
      }
      string _Key;
      public LocalizationExtension(string key)
      {
          _Key = key;
      }
  }

Then I created a helper:

  public class LocalizationHelper 
  {
      static FrozenDictionary<string, string> s_localizationDictionary = FrozenDictionary<string, string>.Empty;
      public static string GetLocalizedString(string key)
      {
          if (s_localizationDictionary is { } && s_localizationDictionary.TryGetValue(k…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by panthernet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants