Try our conversational search powered by Generative AI!

Lee Crowe
May 27, 2011
  4631
(5 votes)

Language File Population Helper VS Macro

Introduction

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!

Feedback?

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

paul.graham@fortunecookie.co.uk
paul.graham@fortunecookie.co.uk 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
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024