none
Change Word 2010 Editing language programatically RRS feed

  • Question

  • Hello

    Does anyone know how to change the Editing language setting below to a different language in C#?

    Im using a 2010 VSTO Ms Word Add-in

    Wednesday, January 25, 2012 11:18 AM

Answers

  • Hi Denys

    A Word document/template carries the language with it - it doesn't matter what language is active on the machine that opens the document. You basically handle it the same way you would any formatting.

    to see what I mean, press Ctrl+A then click the language you see in the status bar. That should display the language dialog box. Select the language you prefer from that, click OK. Now the text will be formatted with that language.

    The equivalent of this in the Word API is Range.LanguageID, for example: Range.LanguageID = Word.WdLanguageID.wdEnglishUK

    That all seems very simple, on the surface, but under the covers Word follows some fairly complicated rules when applying language to text. You might want to fight your way through http://homepage.swissonline.ch/cindymeister/LangFmt.htm, to get an idea of what you're dealing with.

    Ideally, the language would be controlled by setting the property of a style (a concept with which you appear not to be familiar - yet). That would cascade throughout the document. But as soon as a document has been created with a language that doesn't match the system language, this won't work (as described in that article). Then you're in for a fight with Word, as it will try to apply the original language to all new text in the document.

    So, when you open a document in Word you can use something like Document.Content.LanguageID = //the language you want to use and it will be in effect for the existing text in the main body of the document. But no guarantees if the user continues to edit and this will not affect the text in the headers/footers and other document "stories". If you have to handle that, as well, things start to get more complicated...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Denys W Thursday, January 26, 2012 7:02 AM
    Wednesday, January 25, 2012 4:59 PM
    Moderator

All replies

  • Hi Denys

    This isn't a VSTO issue, more an Office configuration question...

    There's nothing in any Office (or VSTO) API that can change the editing language for Office at the level you're showing us. This setting is stored in the Registry, although I can't tell you off-hand in which Key. The folks in the TechNet forums probably know, though.

    Within Word, you'd change the Language property of the Range or, ideally, the Language property of the Style(s) being applied to the text.


    Cindy Meister, VSTO/Word MVP
    Wednesday, January 25, 2012 11:21 AM
    Moderator
  • Hello Cindy

    Ok let me rephrase the question:

    On a machine that is configured as English(U.K) i open a template which displays English(South Africa) in the status bar.

    Please note the machine which is configured as English(U.K) does not have the English (South Africa) enabled 

    This is what lead me to believe that this value is actually stored somehwere when i create the template ion the VSTO add-in which also should mean that it can be changed to somethings else.

    Do you know which property in the add-in stores the English(South Africa) value?

    I understand that the Editing Language is retrieved from the registry but the fact that the language in the status bar is showing the language of the system where the template has been created makes me think that it must be something in word or vsto that sets it...

     

    Wednesday, January 25, 2012 12:56 PM
  • Hi Denys

    A Word document/template carries the language with it - it doesn't matter what language is active on the machine that opens the document. You basically handle it the same way you would any formatting.

    to see what I mean, press Ctrl+A then click the language you see in the status bar. That should display the language dialog box. Select the language you prefer from that, click OK. Now the text will be formatted with that language.

    The equivalent of this in the Word API is Range.LanguageID, for example: Range.LanguageID = Word.WdLanguageID.wdEnglishUK

    That all seems very simple, on the surface, but under the covers Word follows some fairly complicated rules when applying language to text. You might want to fight your way through http://homepage.swissonline.ch/cindymeister/LangFmt.htm, to get an idea of what you're dealing with.

    Ideally, the language would be controlled by setting the property of a style (a concept with which you appear not to be familiar - yet). That would cascade throughout the document. But as soon as a document has been created with a language that doesn't match the system language, this won't work (as described in that article). Then you're in for a fight with Word, as it will try to apply the original language to all new text in the document.

    So, when you open a document in Word you can use something like Document.Content.LanguageID = //the language you want to use and it will be in effect for the existing text in the main body of the document. But no guarantees if the user continues to edit and this will not affect the text in the headers/footers and other document "stories". If you have to handle that, as well, things start to get more complicated...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Denys W Thursday, January 26, 2012 7:02 AM
    Wednesday, January 25, 2012 4:59 PM
    Moderator
  • Hello Cindy

    Thank you, setting Content.LanguageID on start up appeared to have done the trick:

               Globals.ThisDocument.Application.ActiveDocument.Content.LanguageID = Word.WdLanguageID.wdEnglishUK;

    Thursday, January 26, 2012 7:03 AM
  • Hi Cindy, 

    I'm currently facing a very similar issue. My application should set the language of the document based on the selection user made in a combo box with all languages supported. When a document is created, the style language is set properly and actually I set every StoryRange and Content of the document with the proper LanguageID, but it seems useless. If user select German and load a document, at first look it seems fine, but if you start typing something, language is changed to English US. Same behavior if I select English UK, it always change it to English US. Even after doing everything, you go to Review->Language and English US is selected. This behavior is really annoying. 

    I set language in all StoryRanges, I set language in Document.Content, I set language in the Styles, I disable Document.LanguageDetected, and it seems useless. 

    Is there any other thing that I can try?.

    Many thanks in advance.

    -Raul

    Tuesday, December 4, 2012 3:19 PM
  • Hi Raul

    Did you read the link to an article on my website that I gave Denys? Slogging through all that is basis for any discussion you get into with me about language formatting in Word.

    And then I also want to know which version of Word we're dealing with :-)


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 4, 2012 7:41 PM
    Moderator
  • Hi Cindy, 

    Thanks for your reply. I am working with Office Word 2010. And yes, I read your article. Unfortunately, I can change and manipulate the keyboard language in my local machine, but I cannot do the same with the end-user machine. I am also updating normal style based on my specific desired font size and name and also the language. 

    Based on this, I can conclude that there is no way to programmatically set the language of an existing document without Word trying (and accomplish) to change it every time?. Could I consider your post then, as a manual work-around for this issue?. 

    Tuesday, December 4, 2012 7:59 PM
  • Hi Raul

    Do you make sure you're creating the documentn from a "clean" Word 2010 Normal.dotm?

    Is everyone using Word 2010? Which version of Windows is involved?

    I have absolutely no problems on Windows 7, but on some versions of Windows the selected "Input language" can tend to override the "local language" in an application.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, December 5, 2012 7:48 AM
    Moderator
  • Hi Cindy, 

    I am using Word 2010 and my OS is Windows 7. We are launching a specific .dotm file previously created for our application. I have confirmed that this template does not contains any reference to other language and I'm still facing the issue. However, as incredible as it may sounds, I created a VM (Win7 and Word 2010) and language is working perfectly fine there. I have another of my coworkers taking a look into this because we are running out of ideas. Anyway, I really appreciate your suggestions. If I get any solution, I will post it here.

    -Raul

    Wednesday, December 5, 2012 5:04 PM
  • Raul any luck with this? I'm trying to get the "End of Ayah" character to work encapsulating the following three numbers and haven't had much luck. WordPad and OpenOffice seem to render the character fine, while word is having trouble. I am currently running Office '13 after upgrading from 2010 think that might have been the problem.

    maddhater

    Tuesday, October 8, 2013 5:37 AM