none
CultureInfo.CurrentCulture RRS feed

  • Question

  • I have a Word 2007 vsto addin. When I try to get the current culture, English, using:

    CultureInfo.CurrentCulture

    it works. But if I change my culture in Region and Language to German, CultureInfo.CurrentCulture returns English.

    If I close and reopen Word then CultureInfo.CurrentCulture returns German. How do I make this work w/o having to restart Word?


    Richard LT
    Tuesday, December 20, 2011 10:11 PM

Answers

  • Hi Richard LT,

    Thank you for posting.

    I found a way throgh P/Inovke to get the system culture info without restarting the word application:

    using System;
    using Microsoft.Office.Tools.Ribbon;
    using System.Globalization;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace WordAddIn1
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
     
            }
     
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                // use P/Invoke to get local Id
                int lcid = Convert.ToInt32(GetUserDefaultLCID());
                MessageBox.Show(lcid.ToString());
     
                // get the culture info
                CultureInfo ci = new CultureInfo(lcid);
                MessageBox.Show(ci.ToString());
            }
     
            [DllImport("kernel32.dll")]
            static extern uint GetUserDefaultLCID();
        }
    }
    

    Hope this can give you some hint and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Bruce Song Wednesday, January 4, 2012 5:16 AM
    Wednesday, December 28, 2011 6:10 AM

All replies

  • Hi Richard

    Office applications can't change culture while running. This can be seen if one uses the Microsoft Office Language tool to change the user interface language. You'll always get a message that the change cannot take place until the Office apps are closed and restarted.

    Your VSTO add-in is returning the culture for Word, not for your system.

    If you want the current culture of the System I think you'd need to query from a different namespace. Unfortunately, I can't give you that code (because I don't know it). If no one jumps in here I imagine you could find out in a forum that deals with the basic .NET Framework classes.


    Cindy Meister, VSTO/Word MVP
    Wednesday, December 21, 2011 8:12 AM
    Moderator
  • Hi Cindy, I tried

    System.Threading.Thread.CurrentThread.CurrentCulture

    and got the same results.
    Richard LT
    Thursday, December 22, 2011 5:40 PM
  • Hi Richard

    Well, CurrentThread is still going to be the Office thread...


    Cindy Meister, VSTO/Word MVP
    Thursday, December 22, 2011 5:45 PM
    Moderator
  • Richard, have you figured out the problem? If you still show any concern on the problem, just feel free to let us know. Wish you a nice holiday.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 27, 2011 5:06 AM
  • I don't have a fix for this yet.
    Richard LT
    Tuesday, December 27, 2011 2:56 PM
  • Hi Richard LT,

    Thank you for posting.

    I found a way throgh P/Inovke to get the system culture info without restarting the word application:

    using System;
    using Microsoft.Office.Tools.Ribbon;
    using System.Globalization;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace WordAddIn1
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
     
            }
     
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                // use P/Invoke to get local Id
                int lcid = Convert.ToInt32(GetUserDefaultLCID());
                MessageBox.Show(lcid.ToString());
     
                // get the culture info
                CultureInfo ci = new CultureInfo(lcid);
                MessageBox.Show(ci.ToString());
            }
     
            [DllImport("kernel32.dll")]
            static extern uint GetUserDefaultLCID();
        }
    }
    

    Hope this can give you some hint and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Bruce Song Wednesday, January 4, 2012 5:16 AM
    Wednesday, December 28, 2011 6:10 AM
  • Richard, how about the problem on your side? Does the code snippet help you? If you still show any concern on the problem, just feel free to let us know.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 2, 2012 3:28 AM
  • That works. Thank you Bruce!
    Richard LT
    Thursday, January 5, 2012 10:00 PM