c# – What are the ways to internationalize a WPF application?

Question:

Tried creating several buttons in a separate window, when clicking on one of them from Dictionary<string,string[]>languagesDictionary=new Dictionary<string,string[]>(); the required array of strings is searched for by the key and substituted into textBlock and labels of the main window. The code turns out to be very complex and unreadable.

How can you internationalize an application differently?

Answer:

Create a Localization folder (this is not a fixed name, it's just so convenient)

In it, create a resource file (.resx) with the name, for example, UI.resx.

Open it up. At the top, switch the visibility from internal to public.

Fill in the key-row table.

This will be the file for "language neutral".

Then, for each language, create a UI file. <Language code> .resx, it will be something like this.

Localizaion
    UI.resx
    UI.uk.resx
    UI.ru.resx
    UI.ar.resx
    UI.fr.resx

Then in xamle declare the namespace

  xmlns:loc="clr-namespace:MyProject.Localization"

and in the code

  <TextBox Text="{x:Static loc:UI.<Ключ ресурса>}" />
Scroll to Top