locked
VSTO Localization RRS feed

  • Question

  • HI,

       I'm using VSTO in VS.Net 2010 to generate a letter (Word template 2007).  I would like to generate this letter in French or English according to my application user language.  How can I do this?

    Thank you

    Steve

     

    • Moved by SamAgain Friday, September 10, 2010 2:47 AM not clr specific (From:Common Language Runtime)
    Thursday, September 9, 2010 3:54 PM

Answers

  • Hi Steve

    An alternate method would be to store the "boiler text" in a separate document or documents (one document for French, for example and another for English). Use the Range.InsertFile method to bring the text in. This would allow you to insert an entire type of letter, for example.

    Or, you could set it documents to allow a selection for a certain part of a document. A list of greetings, for example. The InsertFile method has a parameter named Range that lets you specify a bookmarked Range in the document you're inserting that brings in only the bookmarked text. You could build lists of the bookmarks in a document to allow the user to choose a greeting (for example).

    This would make it relatively easy for users to manage content directly in a Word document. They'd just have to use some discipline when it comes to marking the text for use. But it shouldn't be a problem for you to design a set of tools to assist with that. For example, they type the text, select it, then your tool takes care of creating the bookmark and anything else you want (such as associating the bookmark name with a description, name of the user who created it, date, etc. and store all this in a CustomXMLPart).


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by SteveGad Friday, September 10, 2010 7:12 PM
    Friday, September 10, 2010 5:28 PM

All replies

  • You don't really explain the specific of what you are trying to culture in your request. Word supports through the API a number of languages and you can set the language using the Object Model with LanguageID on the Selection object, if you are wishing to provide globalisation of the User Interface inside of VSTO this is using the basic .NET Culture classes and can use ResourceManagers to pick the language based on the CurrentUIThread, you can elect to change this at runtime to affectively change the language of the active session, this topic is a little out of scope of VSTO forums but is very possible.

    Regards


    Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers ! Owner and CTO FWBS Ltd http://www.fwbs.net Twitter: www.twitter.com/mikewalker74
    Friday, September 10, 2010 9:22 AM
  • Hi Steve

    As Mike says, you aren't very clear on exactly what you want to do... Looking at the question from another angle - you want the text to be in French or English - there's nothing in VSTO or Word's object model, specifically, that will do any kind of translation for you. You have to store the text.

    May we assume this is a document-level customization (Word template)?

    In that case, one possibility for storing the French vs. English texts would be in BuildingBlockEntries within the template. Your code inserts the appropriate entries, in the desired order, based on what the user wants. It would also be possible to insert BuildingBlock content controls, linked to the specific type of text required/allowed for that section of the document. The user could then select the French or English version.

    Another possibility would be to embed the different "boiler texts" in a CustomXMLPart or Parts. These, however, would be duplicated within and travel with the document (unless you'd remove them), while the building block storage stays in the template.

    As far as Visual Studio goes, there are various strategies for storing/using multi-lingual stuff, but that's not a topic for the VSTO forum, really.


    Cindy Meister, VSTO/Word MVP
    Friday, September 10, 2010 3:26 PM
  • Hi,

       Thank you for your reply.  To answer you question, it is a Word template 2007 I'm using.  My problem with localization in a resource file, is that the document won't be updatable by user.  I would like to be able to put my template on a share drive and allow users to modify the template to avoid lot of work to IT department.  Of course, if the user change the controls in the document, it is normal to involve IT. 

    I know it is possible to create 2 differents documents (one in french and one in english), but they will be in 2 different projects and I don't like the idea to duplicate code or write it in another "shared dll".  The ideal solution would be to have one project containing 2 different versions of the same document, but I didn't see how to do this.  Are BuildingBlockEntries the only way to do this?

     

    Thank you

    Steve

     

    Friday, September 10, 2010 4:55 PM
  • Hi Steve

    An alternate method would be to store the "boiler text" in a separate document or documents (one document for French, for example and another for English). Use the Range.InsertFile method to bring the text in. This would allow you to insert an entire type of letter, for example.

    Or, you could set it documents to allow a selection for a certain part of a document. A list of greetings, for example. The InsertFile method has a parameter named Range that lets you specify a bookmarked Range in the document you're inserting that brings in only the bookmarked text. You could build lists of the bookmarks in a document to allow the user to choose a greeting (for example).

    This would make it relatively easy for users to manage content directly in a Word document. They'd just have to use some discipline when it comes to marking the text for use. But it shouldn't be a problem for you to design a set of tools to assist with that. For example, they type the text, select it, then your tool takes care of creating the bookmark and anything else you want (such as associating the bookmark name with a description, name of the user who created it, date, etc. and store all this in a CustomXMLPart).


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by SteveGad Friday, September 10, 2010 7:12 PM
    Friday, September 10, 2010 5:28 PM
  • Thank you very much for your help.  I will probably use option 2 with CustomXmlPart.

    Thank you

    Friday, September 10, 2010 7:12 PM