<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="buttonText">Hello World!</system:String>
<system:String x:Key="Item was purchased successfully !">Item was purchased successfully !</system:String>
</ResourceDictionary>
<system:String x:Key="Item was purchased successfully !">Item was purchased successfully !</system:String>
.
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="StringResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Application x:Class="DotNetXamlDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="StringResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
<UICulture>en-US<UICulture>
. This line should be inserted after the <Platform> tag under the <PropertyGroup> tag.
Then the project file will look like this :
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<UICulture>en-US</UICulture>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
...
[assembly: NeutralResourcesLanguage("en-US",UltimateResourceFallbackLocation.Satellite)]
msbuild /t:updateuid [.NET Project File]
for example msbuild /t:updateuid DotNetXamlDemo.csproj
.
private void ChangeLanguage(string culture)
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture =
new System.Globalization.CultureInfo(culture);
// Reload all the merged dictionaries to reset the resources.
List<Uri> dictionaryList = new List<Uri>();
foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
{
dictionaryList.Add(dictionary.Source);
}
Application.Current.Resources.MergedDictionaries.Clear();
foreach (Uri uri in dictionaryList)
{
ResourceDictionary resourceDictionary1 = new ResourceDictionary();
resourceDictionary1.Source = uri;
Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
}
Window1 w = new Window1();
w.Show();
this.Close();
}
class TranslateHelper
{
public static string TranslateMessage(string msg)
{
string localizedMessage = (string)Application.Current.FindResource(msg);
return localizedMessage;
}
}
Then use this function to get the localized messages. For example to display a localized message box of "Item was purchased successfully !" write
the following line of code:MessageBox.Show(TranslateHelper.TranslateMessage("Item was purchased successfully !"));
msbuild locbaml.csproj
locbaml /parse [Project Name].resources.dll /out:trans.csv
.
For example , if the project is called DotNetXamlDemo run the following command : locbaml /parse DotNetXamlDemo.resources.dll /out:trans.csv
.
locbaml /generate /trans:[Localized Resources .csv File] /out:..\[Local Culture] /cul:[Local Culture] [Project Name].resources.dll
locbaml /generate /trans:trans.csv /out:..\de-DE /cul:de-DE DotNetXamlDemo.resources.dll