Question regarding localization

Stimulsoft Reports.WPF discussion
User avatar
PJoyeux
Posts: 160
Joined: Tue Nov 26, 2013 9:40 am
Location: Germany

Question regarding localization

Post by PJoyeux »

Hi,

I am trying to offer two UI-Languages: englisch and german. I was able to include both "en.xml" and "de.xml" files in my application (as resources). At runtime I run the following code to set german as localization:

Code: Select all

StiConfig.LoadLocalization(typeof(GeneralPrinting).Assembly.GetManifestResourceStream("AdeptusPrinting.Framework.General.Ressources.de.xml"));
This works, but I want to enable the user to switch between german and english. I know I can set the directory where all available localization-files are placed, but in my case the files are set as resources, so they are not placed somewhere on the PC.

Is there a way to load more than one localization from the resources in order to only show "german" and "english" in this dropdown?
Localization.png
Localization.png (25.94 KiB) Viewed 4827 times
Thanks and cheers,
Pascal
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Question regarding localization

Post by HighAley »

Hello.

Please, try to remove localization files from the application folder.
Also there shouldn't be Localization folder in the folder where you are loading assemblies from.

Thank you.
User avatar
PJoyeux
Posts: 160
Joined: Tue Nov 26, 2013 9:40 am
Location: Germany

Re: Question regarding localization

Post by PJoyeux »

Aleksey Andreyanov wrote:Hello.

Please, try to remove localization files from the application folder.
Also there shouldn't be Localization folder in the folder where you are loading assemblies from.
Ok, this would help reduce the amount of languages shown, but maybe there's a misunderstanding regarding my original question...

I do not want to deploy XML-Files. Rather I want to use embedded XML-Files. This is why I have embedded "en.xml" and "de.xml" as ressourcefiles within my assembly. I was able to load the german localization using the code shown in my first post and could load the english localization using similar code.

But I want to be able to show all available localizations that I have embedded as ressource-files. Since I have embedded only "english" and "german" I want the dropdown to show "english" and "german" although neither file is present on the installation-directory.

I would need code like:

Code: Select all

StiConfig.AddToAvailableLocalizations (typeof(GeneralPrinting).Assembly.GetManifestResourceStream("AdeptusPrinting.Framework.General.Ressources.de.xml"));
StiConfig.AddToAvailableLocalizations (typeof(GeneralPrinting).Assembly.GetManifestResourceStream("AdeptusPrinting.Framework.General.Ressources.en.xml"));
I hope you can now better understand what I mean...

Cheers,
Pascal
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Question regarding localization

Post by HighAley »

Hello.

Unfortunately, it's impossible now. We need some time for analyzing of this issue.
We will answer you this week.

Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Question regarding localization

Post by HighAley »

Hello.

We have added 2 events that you should handle to add several localizations from resources.

Here is a sample code:

Code: Select all

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            StiConfig.LoadLocalization(typeof(MainWindow).Assembly.GetManifestResourceStream("LocalizeResurceDesigner.en.xml"));

            StiWpfDesignerControl designer = new StiWpfDesignerControl();

            designer.LoadCustomerLocalization += new LoadCustomerLocalizationEventHandler(designer_LoadCustomerLocalization);
            designer.CustomerLocalizationChanged += new CustomerLocalizationChangedEventHandler(designer_CustomerLocalizationChanged);

            root.Children.Add(designer);
        }
        
        #region Handler


        private void designer_CustomerLocalizationChanged(object sender, CustomerLocalizationChangedEventArgs e)
        {
            string nameLocalize = e.SelectedLocalization;

            if (nameLocalize.Equals("de"))
                StiConfig.LoadLocalization(typeof(MainWindow).Assembly.GetManifestResourceStream("LocalizeResurceDesigner.de.xml"));
            else if (nameLocalize.Equals("en"))
                StiConfig.LoadLocalization(typeof(MainWindow).Assembly.GetManifestResourceStream("LocalizeResurceDesigner.en.xml"));
        }

        #endregion
    }
In the LoadCustomerLocalization event you could add a list of available localizations.

In the CustomerLocalizationChanged event you could load selected localization from resource.

Thank you.
User avatar
PJoyeux
Posts: 160
Joined: Tue Nov 26, 2013 9:40 am
Location: Germany

Re: Question regarding localization

Post by PJoyeux »

Wow! Thank you! 8-)

I think the handler for designer.LoadCustomerLocalization ("designer_LoadCustomerLocalization") is missing. Could you show me how to add a list of localizations?

Cheers,
Pascal
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Question regarding localization

Post by HighAley »

Hello, Pascal.

Maybe you didn't see the whole sample code. There is a scrolling in the code section in my previous code. You could use it or copy code by clicking on the SELECT ALL.
CodeSection.png
CodeSection.png (19.25 KiB) Viewed 4767 times
Thank you.
User avatar
PJoyeux
Posts: 160
Joined: Tue Nov 26, 2013 9:40 am
Location: Germany

Re: Question regarding localization

Post by PJoyeux »

Yes, I know I can scroll... :D

Maybe I do not understand your code, but I still miss something.

You use the following code to add an event-handler to the event "LoadCustomerLocalization":

Code: Select all

designer.LoadCustomerLocalization += new LoadCustomerLocalizationEventHandler(designer_LoadCustomerLocalization);
But I can't find the declaration for the Even-Handler-Method "designer_LoadCustomerLocalization" where I would have excepted the loading of the two localizations to happen.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Question regarding localization

Post by HighAley »

Hello.

Sorry, I missed some code. Here is it all:

Code: Select all

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            StiConfig.LoadLocalization(typeof(MainWindow).Assembly.GetManifestResourceStream("LocalizeResurceDesigner.ru.xml"));

            StiWpfDesignerControl designer = new StiWpfDesignerControl();
            StiWpfMainMenuService mainMenu = StiWpfMainMenuService.GetService(designer);

            designer.LoadCustomerLocalization += new LoadCustomerLocalizationEventHandler(designer_LoadCustomerLocalization);
            designer.CustomerLocalizationChanged += new CustomerLocalizationChangedEventHandler(designer_CustomerLocalizationChanged);

            root.Children.Add(designer);
        }
        
        #region Handler
        private void designer_CustomerLocalizationChanged(object sender, CustomerLocalizationChangedEventArgs e)
        {
            string nameLocalize = e.SelectedLocalization;

            if (nameLocalize.Equals("de"))
                StiConfig.LoadLocalization(typeof(MainWindow).Assembly.GetManifestResourceStream("LocalizeResurceDesigner.de.xml"));
            else if (nameLocalize.Equals("en"))
                StiConfig.LoadLocalization(typeof(MainWindow).Assembly.GetManifestResourceStream("LocalizeResurceDesigner.en.xml"));
        }

        private void designer_LoadCustomerLocalization(object sender, LoadCustomerLocalizationEventArgs e)
        {
            e.Items = new string[] { "de", "en"};
            e.Processed = true;
        }
        #endregion
    }
Thank you.
User avatar
PJoyeux
Posts: 160
Joined: Tue Nov 26, 2013 9:40 am
Location: Germany

Re: Question regarding localization

Post by PJoyeux »

Hi,

thank you for the code! I was now able to achieve what i wanted...

One thing still: why isn't there a check-symbol in front of the actually selected localization?

In my app it now looks like this:
Bild 1.png
Bild 1.png (6.81 KiB) Viewed 4746 times
in the standalone designer:
Bild 3.png
Bild 3.png (15.68 KiB) Viewed 4746 times
It would be nice to get a check-symbol too...

Cheers,
Pascal
Post Reply