Localization of ribbon

Ribbon for WPF Forum

Posted 6 years ago by Andreas Gruber
Version: 14.1.0601
Avatar

Hello Community!

As we have to translate our UI into russian, i would like to know if there is a file with the needed resource strings that I can translate. How can i apply the new resource strings to the control?

Thank you for your help

Comments (7)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Andreas,

Please check out the topic "Customizing String Resources" in the documentation as that talks about how to customize string resources.  Our Sample Browser app also has a utility in it for viewing all the string resources.


Actipro Software Support

Posted 6 years ago by Andreas Gruber
Avatar

Hi!

I read the topic and had a look into the "String Resource Browser". As i want to switch the language during the runtime, I have the problem that the UI is already loaded and some of the strings would not be replaced with their localized text.

Why dont you use resource files (*.resx; *.resources.dll) for the localization?
The current way for the localization adds a lot of overhead for each programmer, as I have to call the SetCustomString explicit for all the resources that I want to replace.

I hope that I have to call the SetCustomString Method only once for the datatype of the control and not for every instance that I am using?

Thank your for the information

Posted 6 years ago by Corey
Avatar

I ran into the same issue a few months ago. The WPF Localization Extension (also available through NuGet) can help because it makes translating text at runtime much easier, not just for the ribbon but for all your UI text. You'll still have to call SetCustomString for each ribbon resource string every time the language changes and create your own *.resx resources, though.

What you can do is set up a PropertyChanged handler on WPFLocalizeExtension.Engine.LocalizeDictionary.Instance that checks if the Culture property changed and calls a method that calls SetCustomString for each Actipro string resource. Here's an example line:

ActiproSoftware.Products.Ribbon.SR.SetCustomString(ActiproSoftware.Products.Ribbon.SRName.UIApplicationButtonLabelText.ToString(), Properties.ActiproRibbonRes.UIApplicationButtonLabelText);

 Properties.ActiproRibbonRes.UIApplicationButtonLabelText is your own *.resx resource string, but you can replace ActiproRibbonRes and UIApplicationButtonLabelText with whatever your resource names are. I used that naming convention to make Actipro-specific strings easily identifiable.
You do only need to call SetCustomString once for each string resource, but it needs to happen every time the language changes.

You'll also need to edit the XAML styles that use static resource bindings (SRExtension)because you otherwise can't translate that text at runtime. This involves downloading the default styles and templates, copying the relevant files into your application, and changing all instances of SRExtension to LocX extensions pointing to your *.resx resources. An explanation of how to use LocX bindings is in the WPF Localization Extension documentation.
Here are the ribbon XAML styles that use SRExtension:
Gallery.xaml
Menu.xaml
PopupButton.xaml
RibbonWindow.xaml
Screentip.xaml

Hope this helps!

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Andreas,

Actually we do use the standard core .resx method of storing strings.  The SR classes just sit as an access layer on top of those and allow for customization via code.

That being said, some string resources end up in static dependency property declaration defaults, so those wouldn't get updated if you updated them at runtime after they were first used.  However in those cases, there are generally related public properties on control objects that you can set to customize the strings.


Actipro Software Support

Posted 6 years ago by Andreas Gruber
Avatar

Hello!

Well, I meant that I am seeing the resources which I have to translate only through the StringResource Browser. As we are going to translate into a language which I am not speaking we have to use an external company.

Now, i have to type the resources and the identifiers into a Word document so that the translation company can work on the resources. Once they are finished, I have to type again the resources into my resource file.

It would much simpler and less error-prone if you could supply the resx files or something similar (maybe CSV?). Copy the texts into a word document so that the translation company could make their cost estimation.
Send them the resource file with an editor for the translation and receive the translated resources.
Copy them into the solution ...

I hope I have clarified my concerns.
Thanks

Posted 6 years ago by Andreas Gruber
Avatar

I added the following method to the SampleBrowser\Utilities\StringResourceBrowser:

private void WriteResourceTexts(List<ResourceData> resources, string folderPath, string fileName, char separator)
{
   string filePath = System.IO.Path.Combine(folderPath, fileName);

   if (File.Exists(filePath))
   {
      File.Delete(filePath);
   }

   using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
   {
      using (StreamWriter sw = new StreamWriter(fs))
      {
         foreach (var item in resources)
         {
            sw.WriteLine(item.Name + separator + item.Value);
         }
      }
   }
}

 I call the method from the "BindResources" Method in "MainControl.xaml.cs".

This writes the Names and values of the resources into the specified file.

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Andreas,

Good, yes that is what I was going to suggest.  As you saw, it's easy to iterate through that "resources" collection and dump the results to a file format of your choosing.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.