How to set set Addin Express Ribbon language

Add-in Express™ Support Service
That's what is more important than anything else

How to set set Addin Express Ribbon language
 
WSAddInDev




Posts: 38
Joined: 2013-05-13
Hi

I have two concerns

1.
As per the following thread
http://www.add-in-express.com/forum/read.php?FID=5&TID=10352
Addin express picks the language of Office but thats not happening. I have a machine with German OS and Office 2013 in English. The AddinExpress Ribbon is picking language of OS i.e. German.
Why so?? Shouldn't it pick language of office installed.?

2. There are many use cases where a customer has a OS in a language different than the language of Office Installed. So is there any setting of AddinExpress through which i can set the language of the Ribbon.


I have already gone through this code.
private void adxRibbonButton1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
{
if (e.PropertyType == ADXRibbonControlPropertyType.Caption)
{
e.Value = "your localized string";
}
}

Its fine for 1-2 controls but if you are having around 20-30 controls on ribbon and then you need to support more than 3 languages - this code becomes a never ending activity. It hits performance as well.

Please suggest a way to set the language of Addin Express, so that it starts picking the resource strings from the Resource file of corresponding language.
[COLOR=red]
Posted 06 Jun, 2013 06:46:47 Top
Andrei Smolin


Add-in Express team


Posts: 18224
Joined: 2006-05-11
You can modify System.Threading.Thread.CurrentThread.CurrentCulture in the constructor of the add-in module. But it works only if called before InitializeComponent.

Here's a code fragment from HowTo: Avoid “Old format or invalid type library” error:

Dim newCulture As System.Globalization.CultureInfo  
Dim OldCulture As System.Globalization.CultureInfo  
  
OldCulture = System.Threading.Thread.CurrentThread.CurrentCulture  
newCulture = New System.Globalization.CultureInfo( _  
    ExcelApp.LanguageSettings.LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI))  
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture  


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Jun, 2013 07:22:46 Top
WSAddInDev




Posts: 38
Joined: 2013-05-13
Hi

Thanks for the reply. Yes it worked for Addin Express Ribbon - the ribbon got localized.

But now there is one more issue :-

As soon as i open a workbook (Excel 2013) the CurrentCulture is set to the default language of excel.
One solution i see is to reset the CurrentCulture to desired locale by handling the WorkbookOpen event but i have to be sure that Excel don't reset the CutlureInfo elsewhere / in any other action.
Please suggest me a way to achieve it?
Posted 10 Jun, 2013 04:45:47 Top
Andrei Smolin


Add-in Express team


Posts: 18224
Joined: 2006-05-11
Hello,

The code below produces the expected result in Excel 2013 whenever I click the button:


        public AddinModule()
        {
            Application.EnableVisualStyles();
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ru-Ru");
            InitializeComponent();
        }

        private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed)
        {
            MessageBox.Show(System.Threading.Thread.CurrentThread.CurrentUICulture.DisplayName);
        }


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Jun, 2013 11:43:10 Top
WSAddInDev




Posts: 38
Joined: 2013-05-13
Hi Andrei Smolin


I have encountered one more issue now:-

The OS is different from the Language of excel. Our Addin Express ribbon picks the language of OS not Excel.
I want to make our AddinExpress ribbon pick our Excel Language which will be determined at runtime.

Now the code you specified:-

OldCulture = System.Threading.Thread.CurrentThread.CurrentCulture   
newCulture = New System.Globalization.CultureInfo( _   
    ExcelApp.LanguageSettings.LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI))   
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture 


Over here the ExcelApp object is NULL before this.InitializeComponents() in constructor of AddinModule().

If i explicitly make an excel object before this.InitializeComponent(), around 3 excel instances leak and the addin gets disabled next time i open excel.

Can you tell me the way to get the language of excel in AddinModule Constructor before this.InitializeComponen()?

I did some research on my end . User can look up registry values but in that case there are different registry values for different excel version.
Posted 26 Jun, 2013 01:54:12 Top
Andrei Smolin


Add-in Express team


Posts: 18224
Joined: 2006-05-11
Hello,

WSAddInDev writes:
Over here the ExcelApp object is NULL before this.InitializeComponents() in constructor of AddinModule().


You must call that code only when ExcelApp is available. The best moment for doing this is the OnRibbonBeforeCreate event of the add-in module. Only after this, you may call InitializeComponent!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Jun, 2013 04:55:28 Top
WSAddInDev




Posts: 38
Joined: 2013-05-13
Hi Andrei

Thanks for the reply but this didnt help.
I registered the OnRibbonBeforeCre ate event but this gets fired up only after "this.initializeComponent()" of AddinModule. Hence the Ribbon controls have already picked up the language of OS not the one I intend it to pick.
Posted 27 Jun, 2013 02:39:53 Top
Andrei Smolin


Add-in Express team


Posts: 18224
Joined: 2006-05-11
Comment out that call in the constructor and call InitializeComponent() in that event instead.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Jun, 2013 02:57:11 Top
WSAddInDev




Posts: 38
Joined: 2013-05-13
Hi Andrei

I tried doing what you just said.

By that my addin gets disappeared. It shows ticked when i see in the Addins list of Excel->Options->Addins

Here is my code

 public AddinModule()
        {
            Application.EnableVisualStyles();
            this.OnRibbonBeforeCreate += new ADXRibbonBeforeCreate_EventHandler(this.AddinModule_OnRibbonBeforeCreate);
            
            //this.InitializeComponent();
            //// Please add any initialization code to the AddinInitialize event handler
        }
 private void AddinModule_OnRibbonBeforeCreate(object sender, string ribbonId)
        {
            ExcelUtils.SetUICulture(this.ExcelApp);
            System.Globalization.CultureInfo objCultureInfo = new System.Globalization.CultureInfo(Global.CurrentLocale);
            Application.CurrentCulture = objCultureInfo;

            this.InitializeComponent();
        }


ExcelUtils.SetUICulture(this.ExcelApp) is static function which reads the excel language and sets that language as the language of Thread.CurrentThread.CurrentUICulture.
Posted 27 Jun, 2013 04:18:16 Top
Andrei Smolin


Add-in Express team


Posts: 18224
Joined: 2006-05-11
WSAddInDev writes:
ExcelUtils.SetUICulture(this.ExcelApp) is static function which reads the excel language and sets that language as the language of Thread.CurrentThread.CurrentUICulture.


Please refer to the code in HowTo: Avoid "Old format or invalid type library" error.

And I suppose I was wrong suggesting to call InitializeComponent() in that event. I think you ned to split InitializeComponent in two parts:
- everything non-Ribbon-related should be called in the constructor; this is required for the module to be registered
- everything related to localiazing the Ribbon should be called in OnRibbonBeforeCreate

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Jun, 2013 05:00:33 Top