![]() |
Windows App SDK and WinUI 3 Localization and Internationalization |
Windows App SDK (Wikipedia) is Microsoft's application platform for Windows desktop applications, and WinUI 3 is its user interface layer. The platform uses only Unicode, and localized resources are placed in language-specific subdirectories, which makes Windows App SDK one of the best environments for localization. Soluling Desktop and Soluling Cloud support Windows App SDK and WinUI. This page describes Windows App SDK localization step by step.
The end of the document contains links to get the full source code of the samples. After reading this document, we recommend reading a tutorial about how to use Soluling.
WinUI 3 applications use XAML and .resw files with C# or C++. They can also use other resource files, such as images, sound, and video. The following table contains the resource types that Windows App SDK applications use.
| Resource | Description |
|---|---|
| .resw | String resources |
| XAML | User interface resources |
| Images | Image resources |
| Other | Audio, video, XML data, JSON data, text data, etc. |
Whatever the resource file is, the localized resource files are placed in a language-specific subdirectory of the original files. If the original string resource file is
Resources.resw
then the German file is
de\Resources.resw
and the French file is
fr\Resources.resw
You can also use a country-specific subdirectory. The following file is for German (Switzerland):
de-CH\Resources.resw
The Windows App SDK build indexes the localized files into the application's resource file (resources.pri), and the application picks the files of the user's language at run time. You can localize Windows App SDK applications using the following methods.
The Visual Studio project file (.csproj) contains all the information about your application. Add the project file to a Soluling project. When scanning it, Soluling also scans all the resource files it contains. You can turn certain resource types on or off. The advantage of using the project file is that when you add or remove resource files in your application, you don't have to change your Soluling project. When building the project, Soluling writes the localized resources into language-specific subdirectories. Then you build your Visual Studio project to get a multilingual application.
Read the Windows App SDK tutorial to get familiar with this method.
When you localize your Windows App SDK project, you have to select the files that you add to a Soluling project. In most cases, this is easy: you just add your Visual Studio project file or files. However, sometimes you have several project files, or some other file types that are hard to locate. This is why Soluling lets you localize your complete Visual Studio solution. Instead of adding all the project files yourself, you add one file: your Visual Studio solution file (.sln). Soluling reads the solution file and locates all the project files that need to be localized. If you add new projects to your solution, you don't have to change your Soluling project, because Soluling finds the new projects in the solution file.
The result is exactly the same as with the individual project files. Your Soluling project contains the same project sources, you can configure them in the same way, and the output files are the same.
The last method is to localize each XAML file (.xaml) and resource file (.resw) individually. Soluling reads the original resource file and, when building, creates one localized resource file for each language. You have to add all the resource files to your Soluling project, which may be complicated even with wildcards, and every time you add a new resource file, you may have to add it to the Soluling project too. We recommend the Visual Studio project file or solution file method.
This tutorial shows you how to localize a C# WinUI 3 application. The process is the same if you use C++. <data-dir>\Samples\WinUI\Tutorial\Original\Original.csproj is the tutorial application. Open it in Visual Studio. The project contains one window, MainWindow.xaml, that has some text blocks and a button. The text of the first text block is in the XAML file.
<TextBlock>Click the button below</TextBlock>
The text block does not have a name. A name is not required for localization, but without it Soluling cannot give the text a permanent context. Instead, it uses a context that depends on the index of the element, and the context changes if you add or remove elements before it. This is why we recommend giving a name to every element that has text. Let's add it.
<TextBlock x:Name="text1">Click the button below</TextBlock>
The button and the other text blocks already have names, because the code sets their text at run time:
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button> <TextBlock x:Name="text2" Text="dummy" />
The constructor of MainWindow sets the texts, for example:
appWindow.Title = "Click Sample"; text2.Text = "This is a sample";
These strings are hard-coded into the program code, so they cannot be localized. To localize them, we need to replace the hard-coded strings with resource strings.
The first step is to add a string resource file. Right-click the project in Solution Explorer and choose Add | New Item. Select Resources File (.resw), accept the default name, Resources.resw, and click Add. Visual Studio adds an empty resource file.

Copy the "This is a sample" text from the source code and paste it to the Value field. Enter Sample into the Name field. The Comment field can contain any text that gives the translator more information, for example, "Text below the button". Add the window title in the same way, with the name Caption. The resource file looks like this:

The next step is to use the resource strings instead of the hard-coded strings. First, create a ResourceLoader object (Microsoft.Windows.ApplicationModel.Resources) that reads the resource strings:
using Microsoft.Windows.ApplicationModel.Resources;
public sealed partial class MainWindow : Window
{
private ResourceLoader rl = new ResourceLoader();
This creates the object and makes it available to all the methods of MainWindow. Next, replace the hard-coded strings with calls to rl.GetString:
appWindow.Title = rl.GetString("Caption");
text2.Text = rl.GetString("Sample");
The parameter is the name of the resource string, the value in the Name field of the resource file.
The next hard-coded string is a little more complicated.
text3.Text = "My name is " + name;
The value of the Text property is a combination of a constant string and a variable. If name is "John", the string is "My name is John". If it is "Mary", the string is "My name is Mary". We could use the same approach as with text2:
text3.Text = rl.GetString("Name") + name;
However, this assumes that the name is always the last word of the sentence. This works in many languages, such as English, German, and Finnish. However, in Japanese you would say "マリーです", where マリー is the name and です is "My name is". To create correct Japanese, the code would have to be
text3.Text = name + rl.GetString("Name");
Our code has to work in both English and Japanese, so we need a more general solution: message patterns. Instead of "..." + name, we use String.Format, which combines a message pattern with the values. The message pattern is a string that contains placeholders for the values. A placeholder is {x}, where x is the index of the value: 0 is the first, 1 is the second, and so on. With a message pattern, the line is
text3.Text = String.Format("My name is {0}", name);
Add "My name is {0}" to the resource file with the name Name. The final line is:
text3.Text = String.Format(rl.GetString("Name"), name);
Now the translator can move the placeholder wherever the grammar of the target language requires. The following table contains the pattern in a few languages:
| Language | Pattern |
|---|---|
| English | My name is {0} |
| Finnish | Nimeni on {0} |
| Japanese | {0}です |
Most languages use plural forms: the noun of the sentence is singular or plural depending on the number of objects. For example, we say "Clicked 1 time" but "Clicked 2 times". How can our code create a grammatically correct dynamic message? One approach is to use an if statement:
if (count == 1)
myButton.Content = $"Clicked {count} time";
else
myButton.Content = $"Clicked {count} times";
The above code has two issues. First, it uses string interpolation. You cannot localize an interpolated string. Use String.Format with a pattern instead. Second, the code only works in languages that use the singular with one and the plural with all other numbers, such as English, German, and Finnish. French uses the singular with 0 and 1, Japanese does not have plurals at all, and Polish has separate forms for 1, for 2-4, and for 5 or more. Handling all languages in your own code would be very complex, and Windows App SDK does not offer a solution. Soluling does: Soluling.MultiPattern.Format is a plural-enabled format function similar to String.Format. To use it, add the <data-dir>\Library\NET\Standard\Soluling.csproj library project to your solution and reference it from your project. Now we can use the following line.
myButton.Content = Soluling.MultiPattern.Format("{plural, one {Clicked {0} time} other {Clicked {0} times}}", count);
The original language is English, and it has two forms, so the pattern contains two parts: one for the singular and other for the plural. The second parameter of MultiPattern.Format is the count that selects the plural form. The rest of the parameters work like in String.Format: they are the values that are inserted into the placeholders. The translator enters a pattern for each plural form that the target language uses. The following table contains the pattern in a few languages:
| Language | Pattern |
|---|---|
| English | {plural, one {Clicked {0} time} other {Clicked {0} times}} |
| Finnish | {plural, one {Klikattu {0} kerran} other {Klikattu {0} kertaa}} |
| Japanese | {plural, other {{0}クリック}} |
Soluling has a plural editor that lets you easily and safely edit each pattern. The plural engine must know the current language. There is no 100% accurate way to get the language of the resources that the application uses, so the best way is to set the language yourself:
Soluling.Language.Id = rl.GetString("Language");
The Language resource string contains en, the ISO code of English. Each translated resource file contains the code of its language. For example, the German resource file contains de. After initializing the engine, we can use it. Add the pattern to the resource file with the name ClickedTimesPlural. The final line is:
myButton.Content = Soluling.MultiPattern.Format(rl.GetString("ClickedTimesPlural"), count);
We have one more thing to do. Look at the following line:
text4.Text = "Today is " + today.Month + "/" + today.Day + "/" + today.Year % 100;
It converts a date into a string. In the US, this would be, for example, "Today is 1/14/16". We could use a message pattern like this
text4.Text = String.Format("Today is {0}/{1}/{2}", today.Month, today.Day, today.Year % 100);
but it would only work in the US and other countries that use month/day/two-digit year. For example, in Finland, the correct format is 14.1.2016: the order is day, month, and year, the separator is a period, and the year has four digits. Windows has an API that creates correct date strings: the Windows.Globalization.DateTimeFormatting.DateTimeFormatter class. First, create a date formatter using the short date format and the languages of the user:
var formatter = new DateTimeFormatter("shortdate", GlobalizationPreferences.Languages);
Then use its Format method to convert a date into a string:
text4.Text = String.Format(rl.GetString("Today"), formatter.Format(today));
The Today resource string is "Today is {0}", and formatter.Format(today) returns the date in the short date format of the user's language. Now the internationalization is finished, and we can start localizing the project.
Start Soluling and click the New from File or Files button. Browse to the <data-dir>\Samples\WinUI\Tutorial\Localized directory and select Localized.csproj.

Click Next. Soluling shows a dialog to choose the file type.

Accept the detected type, Windows App SDK/WinUI project file, and click OK. The Resources page appears. It shows the available resource types. We don't need to localize images, so uncheck Image resources.

Click Next. The Select Languages page appears. It lets you choose the target languages. Drag the languages you want from the left list to the right list. In our sample, we use Finnish.

Click Finish to complete the wizard. Soluling creates a new project, reads Localized.csproj, scans the resource files it contains, and shows the created project in the editor.

The project tree shows the sources on the top level. Our sample contains one source, Localized.csproj. Each source contains rows and subnodes, and each subnode is one resource file. For example, Resources.resw contains the string resources. When you select a node in the project tree, the grid shows only the rows of that node and its subnodes. Our project contains a resource file that we do not want to localize. Select App.xaml, right-click, and choose Exclude.

Now App.xaml is excluded from the project. MainWindow.xaml contains a row that has dummy text. It is the design-time value of the Text property, which the code replaces with a resource string at run time, so we do not localize it. The easiest way is to exclude all the "dummy" strings. Select a "dummy" row, right-click on the left side of the row in the grid, and choose Exclude | All Rows with "dummy" original.

Soluling prompts you to rescan. Accept it. Once scanned, the project is ready for translation.

The rightmost column of the grid contains the Finnish strings. There are no translations yet, so all values are empty. Start typing translations. You can also use machine translation: right-click the Finnish column header and choose Machine Translate. Rows that have plural forms show a double bubble in the info column. To enter their translations, Soluling shows a plural editor.
![]()
You can also edit the plurals in a dialog. Right-click the translation cell and choose Edit.

The editor shows the original forms. The original language is English, so the original forms are singular and plural. Finnish also has two forms: singular and plural. Enter the translations and click OK. Once you have translated all the rows, the project looks like this.

Now we can create the localized resource files. Click the Build button on the ribbon. Soluling creates the localized resource files fi\Resources.resw and fi\MainWindow.xaml.

The XAML and .resw files in the language subdirectories are included in the build automatically. For any other resource type, such as images or text files, set the Build Action of the localized file to Content in your Visual Studio project.
When you build your application, Visual Studio may warn that you have "fi" resources but no "en" resources for the default language. The "en" resources are not needed, because the project contains the original neutral resources. At run time, Windows App SDK uses resource cascading: if the resources of a specific language are not found, the default resources are used, and if they are not found either, the neutral resources are used.

You can ignore this warning.
Now we have a multilingual application that supports English and Finnish. Let's run it. On English Windows, or any Windows that does not have Finnish in its preferred languages, the application starts in English.

Start Settings, select the language settings, and you see your preferred languages. Add Finnish as the topmost language.

Run the application again, and now it appears in Finnish.

<data-dir>\Samples\WinUI\Tutorial\Localized\Localized.csproj is the tutorial project, fully internationalized and localized into Finnish.
In our sample, we localized XAML and .resw files. Soluling can localize all kinds of resource files. If you have image or sound files in your project, Soluling lets you easily specify a language-dependent version of the file. See the <data-dir>\Samples\WinUI\Resources sample to see how images, audio, XML, structured text, and segmented text are localized.

In addition to the above resources, Soluling can localize plain text, JSON data, image lists, video, or any binary data. After building the localized files, remember to set the Build Action of the media resources (text, XML, image, etc.) to Content in your Visual Studio project. Do not change the Build Action of XAML and .resw files.
Localized.csproj) or solution file onto Soluling or click the New from File or Files button and select the file.fi\Resources.resw and fi\MainWindow.xaml.When you change your application, open the Soluling project and choose Home | Scan. Soluling keeps the existing translations, and you only translate the strings that were added or changed. Then build again.
With Soluling Cloud, you and your translators translate the application in a browser using Translate. Soluling Cloud cannot read a Windows App SDK project itself, so you create the project in Soluling Desktop, upload it to Soluling Cloud, and build the localized files in Soluling Desktop. You need a Soluling account. See the available Cloud plans.
.ntp).The project now also appears on the dashboard (Cloud > Dashboard for Projects, Users and Terminology at www.soluling.com), marked as created from a .ntp file.
Click the project's green Translate button on the dashboard. Translate opens the project, and you can type the translations into the grid. Machine translation suggestions, translation memory, and spell checking are available there. You do not have to finish every language before moving on to the next step.
To let translators do the work, click the project's Manage button and invite a translator for each language under Languages and Invitations.
In Soluling Desktop, on the Translate tab, click Import from Cloud. Soluling downloads the translations made in the cloud and imports them into your local project. Then choose Home | Build All, and build your application in Visual Studio.
When you change your application, in Soluling Desktop, on the Home tab, click Scan so the project picks up the changes. On the Translate tab, click Upload to Cloud. The cloud project is updated to match your local one, and translations that exist only in the cloud so far are kept. Translate the new and changed strings in Translate, then Import from Cloud and build again.
To do the same steps from a build script, use SoluMake. See the Cloud tutorial.
GitHub and <data-dir>\Samples\WinUI contain the following Windows App SDK samples:
| Directory | Description | Notes | ||||
|---|---|---|---|---|---|---|
| Tutorial | The tutorial application that shows you how to internationalize a Windows App SDK application. It contains the following projects:
|
Try this first! | ||||
| Resources | A C# application that shows how to localize other kinds of resources, such as images, sound, XML, and text files. The application reads them through the resource manager of Windows App SDK. |
WinUI.sln is a Visual Studio solution file that contains all the above samples. The samples target .NET 10 and Windows App SDK 1.8. Localized uses the Soluling library project, <data-dir>\Library\NET\Standard\Soluling.csproj.
You can configure how to localize your Windows App SDK project file (.csproj) by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.
You can configure how to localize your Windows App SDK resource file (.resw) by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.