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
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:
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 ) 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