armat.localization.wpf
1.2.2
See the version list below for details.
dotnet add package armat.localization.wpf --version 1.2.2
NuGet\Install-Package armat.localization.wpf -Version 1.2.2
<PackageReference Include="armat.localization.wpf" Version="1.2.2" />
<PackageVersion Include="armat.localization.wpf" Version="1.2.2" />
<PackageReference Include="armat.localization.wpf" />
paket add armat.localization.wpf --version 1.2.2
#r "nuget: armat.localization.wpf, 1.2.2"
#:package armat.localization.wpf@1.2.2
#addin nuget:?package=armat.localization.wpf&version=1.2.2
#tool nuget:?package=armat.localization.wpf&version=1.2.2
Armat Localization Wpf
The document describes Armat Localization Wpf .Net library. Being an extension of Armat Localization Core, it provides APIs for localizing Wpf applications.
See more details in https://github.com/ar-mat/Localization/tree/main/Projects/Localization.Core.
LocalizableResourceDictionary class
Represents a type derived from ResourceDictionary of Wpf resources. The dictionary key (aka resource key) is used to retrieve appropriate localized values.
LocalizableResourceDictionary can be loaded from Wpf assembly resource, as well as from a local file. The class is used for retrieving translated strings at application runtime.
Following is the format for LocalizableResourceDictionary resource files:
<l_wpf:LocalizableResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=netstandard"
xmlns:l_wpf="clr-namespace:Armat.Localization.Wpf;assembly=armat.localization.wpf">
<s:String x:Key="MessageBox_Caption_Info">Information</s:String>
<s:String x:Key="MessageBox_Caption_Warning">Warning</s:String>
<s:String x:Key="MessageBox_Caption_Error">Error</s:String>
</l_wpf:LocalizableResourceDictionary>
LocalizableResourceDictionary class has the following members:
LocalizationManagerproperty can be set to attach the resource dictionary instance to the localization manager. Upon locale change in the localization manager, the appropriate translation will be loaded in theLocalizableResourceDictionary.TranslationsDirRelativePathproperty holds the path to the translations directory in case LocalizationManager.Configuration.TranslationsDirectoryPath should be overridden.CurrentLocaleproperty represents theLocaleInfocurrently loaded in the resource dictionary.GetValueOrDefaultmethod can be used to retrieve the translated value from dictionary if available, or the given default value otherwise.
There are more LocalizableResourceDictionary APIs used internally. Description for those will be provided together with the usage.
General Usage Pattern
The usage pattern will be demonstrated on a sample of Wpf application. It's available through Armat Localization Demo GitHub link.
Create LocalizationManager
- Create LocalizationManager
Configurationby specifying the default locale for the application. - Instantiate the default
LocalizationManagerupon application startup viavar lm = LocalizationManager.CreateDefaultInstance(cfg);. - Select application runtime language via
lm.ChangeLocale("en");in case it is different from the default locale. - Register to
LocalizationManager.Default.LocalizationChangedevent wherever the application must react to the language selection operation.
Create LocalizableResourceDictionary
- Create a Wpf Resource Dictionary file in Localization folder of the project. Format of the localizable file is described above.
- Define keys and values in localizable resource dictionary file. Values should be defined in native language and will be used in case the translations aren't found / loaded.
- Add the localizable resource dictionary as a merged dictionary in appropriate Wpf xaml controls and windows.
- Prefer using LocalizableResourceDictionary.GetValueOrDefault to read localized values in case the strings are used in a c# class, not in xaml files.
Use Localization.Designer
- Localization Designer source code is available here.
- Instead of manually creating translation files for each language, Localization Designer can be used to easily load & translate localizable files. It will create corresponding translation files in appropriate directories.
- Set "Copy to output directory" of generated translation files to "Copy if newer" in Visual Studio. Those will appear in the appropriate Localization subfolders in the bin directory.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. net9.0-windows was computed. net10.0-windows was computed. |
-
net6.0-windows7.0
- armat.localization.core (>= 1.2.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.