Andrey Moiseev Andrey Moiseev - 3 years ago 202
C# Question

How to localize Neutronium-based UI using .RESX files?

I use Neutronium library for a HTML-based C# UI.

I want to be able to use strings from a .RESX resource conveniently, not wrapping every string in a resource-accessing property of the ViewModel.

How achieve this more easily?

Answer Source

You can use ResourceManager.GetResourceSet to convert resource in a dictionary and then use this dictionary in the ViewModel

Here is a complete solution compatible with upcoming version 1.0.0


public class MainViewModel : ViewModelBase
   private Dictionary<string, string> _Localization;
   public Dictionary<string, string> Localization
       get { return _Localization; }
       private set { Set(ref _Localization, value, nameof(Localization)); }

   private string _Langage;
   public string Langage
        get { return _Langage; }
            if (Set(ref _Langage, value, nameof(Langage)))

   private void UpdateLangage()
       var rs = Resource.ResourceManager
                        .GetResourceSet(new CultureInfo(_Langage), true, true);
       Localization = rs.Cast<DictionaryEntry>()
                        .ToDictionary(dicEntry => (string)dicEntry.Key, dicEntry => (string)dicEntry.Value);            

   public string[] Langages => new[] {"en-US", "pt-BR", "fr-FR"};

   public MainViewModel()
     Langage = "en-US";

Vue file:

        <div id="app" class="fluid container">
            <div id="main-menu" class="jumbotron logo">
                <img src="./assets/logo.png">

            <div class="col-md-2">
                <select v-model="Langage">
                    <option v-for="lang in Langages" :value="lang">{{lang}}</option>

            <div class="col-md-10">

Complete solution here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download