1
votes

I'm currently struggling with some special case in localization. I read about the different approaches to localize a WPF application and decided to go with satellite assemblies, generated by "locbaml". In order to be able to localize strings from c#-code I decided to use resourcedictionaries as described here: http://msdn.microsoft.com/en-us/library/bb613547%28v=vs.110%29.aspx
So I have this resource dictionary:

<ResourceDictionary x:Uid="ResourceDictionary_1" 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:Uid="system:String_1" x:Key="TestKey">Development</system:String>
</ResourceDictionary>

I merge it within the app.xaml:

Application x:Uid="Application_1" x:Class="LocalizationIssue.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary x:Uid="ResourceDictionary_1">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Uid="ResourceDictionary_2" Source="Localization.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

This should enable me to do something like that:

this.Message = (string)Application.Current.FindResource("TestKey");

And it does. When I launch the application I can see "Development". My sample project just has two Textblocks. The TextProperty of one TextBlock is bound to a property called "Message". The other one is set statically to "StaticDevelopment". So the MainWindow.xaml looks like that:

<Window x:Uid="Window_1" x:Class="LocalizationIssue.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel x:Uid="StackPanel_1">
        <TextBlock x:Uid="TextBlock_1" FontSize="20" Text="{Binding Message}" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <TextBlock x:Uid="TextBlock_2" FontSize="20" Text="StaticDevelopment" VerticalAlignment="Center" HorizontalAlignment="Center" />
    </StackPanel>
</Window>

Then I followed all the steps to create satellite assemblies with locbaml as described here: http://msdn.microsoft.com/en-us/library/ms746621%28v=vs.110%29.aspx
i.e.: 1. Add UICulture to project file (and also to assemblyinfo)
2. Create uids: msbuild /t:updateuid LocalizationIssue.csproj
3. Create csv-file: locbaml /parse LocalizationIssue.resources.dll /out:loc.csv
4. Translate values in loc.csv
5. Create sattelites: locbaml /generate LocalizationIssue.resources.dll /trans:loc.csv /out:c:\ /cul:en-US
Now, when I switch the UI culture to french it still shows the english translation for the TextBlock with the binding but the localized value for the other textblock.
Any ideas what I'm doing wrong? What's your experience with the "locbaml"-approach? Should we go the traditional way with resx-files?

Thanks for any input ;)

2

2 Answers

0
votes

Try copying to a new file may be loc_us.csv and make changes then run locbaml /generate LocalizationIssue.resources.dll /trans:loc_us.csv /out:c:\ /cul:en-US

0
votes

I know this one is old but hopefully this will save someone some time.

I followed the same steps and got the same results as detailed in the original post by CrazyChief. The step I missed was to add xml:lang="en-US" to my resource dictionary like so

<ResourceDictionary x:Uid="ResourceDictionary_1" 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"
                    xml:lang="en-US">
    <!-- String resources that can be localized -->
    <system:String x:Uid="system:String_1" x:Key="success">Success</system:String>
</ResourceDictionary>

After I made this change and rebuilt the project, I was able to use locBAML to export the CSV from the en-US satellite assembly, make the translation, and generate a fr-CA satellite assembly from it.