Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Lee Crowe
May 27, 2011
(5 votes)

Language File Population Helper VS Macro


For the last six months or so I have been working on a large global EPiServer build.  After a few weeks working on the project one of my colleagues Paul Graham soon got fed up of populating the language files with translatable text and decided to write a Visual Studio Macro to help with the language file population.

A few days ago Thomas Krantz blogged about an Add-in for VS he had created to order nodes within a language file.

After reading the blog post I added a comment to the post asking if anyone one be interested in a utility to help with language file population.  I had a few responses so I decided to revisit the original Macro code and enhance/refactor it and make it more usable for a wider audience.

What does the EPiServerLanguageFiles VS Macro do?

The macro will allow the developer to select text within a project file (.aspx, .ascx, .cs etc) and then will insert the necessary nodes into the relevant language xml files.

The macro will initially create a new language file within the lang folder based on the solution name.  It would be the users responsibility to create all of the other relevant language specific xml files.  The naming convention of the files should follow something like “AlloyTech_EN.xml”.

When updating the language files the Macro would look for all files matching a pattern similar to “AlloyTech_*.xml”.

Full usage instructions are detailed further down in the blog post.


EPiServerLanguageFiles VS Macro Installation

To setup the macro in Visual Studio you will need to follow the steps below:

1. Download the macro source from here.

2. Load up visual studio and press ALT + F11 to take you to the “Microsoft Visual Studio Macro” editor.  Right click on MyMacros and add a new Module named “EPiServerLanguageFiles”.

3. Overwrite the contents of the module with the VB code you downloaded in step 1.

4. Right click the references node under the MyMacros project and add a reference to System.Xml if it is not already referenced.

5. Right click the MyMacros project and build it.

6. Close the Visual Studio Macro Editor.

7. Add a new toolbar to Visual Studio by right clicking on the toolbar area and clicking customize.  Click new and enter “EPiServerLanguageFiles” as the name.  A new toolbar will now be visible.

8. Click the down arrow associated with the new toolbar and click “Add or Remove Buttons” then “Customize”.  Click “Add Command”, select the “Macros” category and then select the Macro ending in the name .EPiServerLanguageFiles.UpdateSelection.  Click the “Modifiy Selection” button and change the name to “Translate”.

9.  The macro is now setup and you can close the Macro Editor Smile


EPiServerLanguageFiles VS Macro Usage

The usage instructions below are written against the AlloyTech public demo website.

Within the AlloyTech site I have the following language files:

The Macro will work with files matching the following file pattern within the lang folder “SolutionName_*.xml”.  So when using the Macro with the AlloyTech solution only files matching the “AlloyTech_*.xml” file pattern will be updated. 

The Macro will create an initial file if no matching files exist. 

It would be the responsibility of the developer to create other language specific files.  The default files language code and name will be based on the following fields within the macro:

  • DefaultLanguageName
  • DefaultLanguageCode

The steps below demonstrate how I would get a paragraph of text into all of the language files:

1. Select some text within the Document.aspx template file and then click your new ‘Translate’ button.

2. You will firstly be presented with an InputBox (This brings back some memories of the good old Fox Pro and VBA days Winking smile) which will prompt you for a replacement type.  Here you enter a number matching the output you require and press Enter.  I will use the default for a Literal control.

3. You will then be asked if you would like the element being placed into the language files to be a common element.  All common elements will be placed within a ‘common’ element which lives directly under the language node.  Otherwise the element hierarchy will be based on the name of the file the selected text lives in.

4. You will then have another prompt asking you for the key name.  By default this will be made up of the selected text with invalid characters removed.  Change the key text if you are not happy with it and press Enter.

5. The selected text will now be replaced with a literal control like the following: <asp:Literal runat="server" EnableViewState="false" Text="<%$ Resources: EPiServer, document.content.thealloytechwebsiteisgreat%>"/>

You will notice that the hierarchy is based on the current template name “document.content.thealloytechwebsiteisgreat”.

6. The relevant xml files will also be updated see below:

Have a play

Please have a play with it preferably in your own AlloyTech site first and see what you think!


I hope people find this Macro useful, maybe people could further enhance it and share the enhancements with the community.

I am always eager to receive feedback good and bad. 

Please feel free to email or twitter me with any feedback @croweman or comment on the blog post Smile

May 27, 2011

Comments May 27, 2011 11:48 AM

With tedium come mistakes.

May 27, 2011 12:54 PM

This sounds like something I wanna try out asap. Nice one.

Thomas Krantz
Thomas Krantz May 27, 2011 12:59 PM

Nice work, I'll try it out.

May 27, 2011 04:33 PM

Looks pretty awesome, it would be great to do something similar to insert page property references too?

Please login to comment.
Latest blogs
Copying property values part 2

After publishing my last article about copying property values to other language versions, I received constructive feedback on how could I change t...

Grzegorz Wiecheć | Jun 18, 2024 | Syndicated blog

Enhancing online shopping through Optimizely's personalized product recommendations

In this blog, I have summarized my experience of using and learning product recommendation feature of Optimizely Personalization Artificial...

Hetaxi | Jun 18, 2024

New Series: Building a .NET Core headless site on Optimizely Graph and SaaS CMS

Welcome to this new multi-post series where you can follow along as I indulge in yet another crazy experiment: Can we make our beloved Alloy site r...

Allan Thraen | Jun 14, 2024 | Syndicated blog

Inspect In Index is finally back

EPiCode.InspectInIndex was released 9 years ago . The Search and Navigation addon is now finally upgraded to support Optimizely CMS 12....

Haakon Peder Haugsten | Jun 14, 2024