LangLib – WPF localization using Uids

LangLib – WPF localization using Uids

Since version 1.1.0.1 of the LangLib (MultiDB) and v.1.0.0.5 (SQLite) it has had a possibility to use FrameworkElement.Uid for localization.

It’s not recommended that you give the x:Uid values to XAML yourself but use a tool to generate them.

The x:Uid values are generated using MSBuild tool. The basic syntax is MSBuild.exe /t:updateuid YourProjectFile.csproj and MSBuild.exe /t:checkuid YourProjectFile.csproj.

The easiest way is to add these commands to application’s Pre-build event command line:

The Pre-build event command line as text

$(FrameworkDir)\MSBuild.exe /t:updateuid “$(ProjectPath)”
$(FrameworkDir)\MSBuild.exe /t:checkuid “$(ProjectPath)”

As seen in my test project there is no x:Uid tags in the XAML yet:

Lets build

Select the application and select Build

The Visual Studio IDE immediately notifies that some files in the solution have been changed:

Lets select the “Yes to All” button.

The build output should look something like this

1>—— Build started: Project: UidTest, Configuration: Debug Any CPU ——
1> Microsoft (R) Build Engine version 4.6.79.0
1> [Microsoft .NET Framework, version 4.0.30319.42000]
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> Build started 3.11.2015 17:01:16.
1> Project “C:\Users\Petteri Kautonen\Documents\Visual Studio 2013\Projects\UidTest\UidTest\UidTest.csproj” on node 1 (updateuid target(s)).
1> UpdateUid:
1> Checking Uids in file ‘MainWindow.xaml’ …
1> Checking Uids in file ‘App.xaml’ …
1> Uids updated in 2 files.
1> Done Building Project “C:\Users\Petteri Kautonen\Documents\Visual Studio 2013\Projects\UidTest\UidTest\UidTest.csproj” (updateuid target(s)).
1>
1> Build succeeded.
1> 0 Warning(s)
1> 0 Error(s)
1>
1> Time Elapsed 00:00:00.55
1> Microsoft (R) Build Engine version 4.6.79.0
1> [Microsoft .NET Framework, version 4.0.30319.42000]
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> Build started 3.11.2015 17:01:17.
1> Project “C:\Users\Petteri Kautonen\Documents\Visual Studio 2013\Projects\UidTest\UidTest\UidTest.csproj” on node 1 (checkuid target(s)).
1> CheckUid:
1> Checking Uids in file ‘MainWindow.xaml’ …
1> Checking Uids in file ‘App.xaml’ …
1> Uids valid in 2 files.
1> Done Building Project “C:\Users\Petteri Kautonen\Documents\Visual Studio 2013\Projects\UidTest\UidTest\UidTest.csproj” (checkuid target(s)).
1>
1> Build succeeded.
1> 0 Warning(s)
1> 0 Error(s)
1>
1> Time Elapsed 00:00:00.05

Lets see how the XAML did change:

All the FrameworkElement descendants now have an x:Uid value thus they can now be localized by the LangLib.

Disabling the Uid / x:Uid generation while developing

You can use any batch script commands / markings to disable the Uid / x:Uid generation such as echo, rem or ::.

For example echo just echoes the commands before build:

And the build result:

This way you can even copy the commands to run them outside the IDE.

The :: mark before a command is a commend so nothing gets echoed.

After this your WPF application can be localize with the DBLangEngine.

Thanks for your interest 🆒