Click here to Skip to main content
12,953,007 members (70,096 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 19 Sep 2007

Project Localizer

, 13 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A tool for localizing source files and generating helper classes in any programming language
Screenshot - ProjectLocalizer_1.gif


Project Localizer is a tool to localize any kind of source file. What does it mean, exactly? The tool does two things:

  1. Replaces all strings in a source file with a specified expression, e.g.
    MessageBox.Show("I like you.");
    MessageBox.Show(localizer["ILikeYou"]);  // XML localizer
    MessageBox.Show(localizer.ILikeYou);  // hard-coded localizer
  2. Generates localizer files in any programming language using a predefined template, e.g. an XML file:
        <language name="English">
            <string id="ILikeYou">I like you.</string>
    or a hard-coded localizer:
    interface ILocalizer
        string ILikeYou { get; }
    class EnglishLocalizer : ILocalizer
        public string ILikeYou get { return "I like you."; }


Sometimes a small project suddenly becomes a big project and we want to make it more global. If we were not provident enough to use resource files, we could come across tens of source files full of not localized (likely English) strings inside. So, we set our shoulder to the wheel and start to rewrite the whole code... Or we use some smart tool, like Project Localizer.

Using the Code

I have written a GUI (Graphics User Interface) for my tool and nothing else because there are two stages of localizing source files.

  1. Parse the source files.
  2. Choose which strings should be localized and name the variables (like ILikeYou for "I like you").

If the modified files don't compile, some manual corrections may be required. However, I did my best to prevent such situations.

The Project Localizer

After starting the application, you will see a window with three frames. With the one on the top, you can set the behaviour of the localizer. The most important properties are:

  • InputType - sets which property should be used as a source of files, InputDirectory or InputFiles.
  • InputDirectory and InputFiles - sets a location of source files to localize.
  • Template - sets how a generated localizer should look. I give you two ready-to-use templates, which can be accessed via xml.txt and hard.txt. See the Templates chapter to learn how to create templates.
  • All the rest properties are described in the program.

When everything is set up, press the rosy button "Process files." Then will appear all files that were successfully processed. If you click on any of them, then a grid with all strings found in a source file will be displayed. You can specify there:

  • Create checkbox - determine whether an entry should be included in a resource file.
  • Use checkbox - determine whether a string in a source file should be replaced with an expression referencing a generated resource entry.
  • C & U checkbox - sets both Create and Use.
  • Name of the variable field - A name of an entry in a resource file.
Screenshot - ProjectLocalizer_1.gif

Don't create and don't use buttons just to make your task easier. If you have already chosen which strings should be localized and how, then press the "Generate files" button. New files will be generated in the folder specified in the OutputDirectory property.


As I mentioned in the Introduction, my tool is language-independent because it uses templates. Now I would like to explain how to create them. templates\hard.txt is a template that generates hard-coded localization classes.

### SET getter=LC.Localizer.$
### HEADER using Gajatko.ProjectLocalizers.LC;
### FILE $sourceName$_hardloc.cs
namespace Gajatko.ProjectLocalizers
    partial interface IHardCodedLocalization
        string $variableName$ { get; }$endLoop$
    partial class $language$HardCodedLocalization : IHardCodedLocalization
        public string $variableName$
            get { return $content$; }
### FILE localizer.cs
using Gajatko.ProjectLocalizers;
namespace Gajatko.ProjectLocalizers.LC
    static class LC        // ("LocalizerContainer")
        public static IHardCodedLocalization Localizer = 
            new $language$HardCodedLocalization();

I think that construction of this file is self-explanatory in most cases. ### SET getter enables us to specify an expression used to replace strings in a source file, where the $ (dollar) sign represents a name of a resource entry. A $loop$ - $endLoop$ block says to the interpreter that a block should repeated for each string. ### FILE blocks are responsible for creating new files. Other variables enclosed in dollar signs are referencing particular properties.


The solution includes Project Localizer itself and two demos. The Windows Forms application sample uses XML templates and the Console program uses a hard-coded localizer.


  • Project Localizer supports strings prefixed with @ (ignoring escape characters) known from C#. However, this functionality can be turned off by setting the AllowIgnoreEscape property to false.
  • When using XML resource files, escape characters found in source files like \" are converted to their generic equivalents, like ". Also, critical for XML characters like ampersand or triangle brackets are converted to their HTML equivalents: &amp;, &lt;, etc.

Points of Interest

From my point of view, I have everything that I need. However, if you have created a new template for your use, especially in another language than C#, then please send it to me and I will upload it here.


  • 19 September, 2007 -- Original version posted
  • 13 May, 2008 -- "Index out of bounds" bug fixed


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jacek Gajek
Software Developer (Junior)
Poland Poland
My name is Jacek Gajek. I have graduated in computer science with a master's degree from Polibuda in Wrocław. I like C# and Monthy Python's sense of humour.

You may also be interested in...

Comments and Discussions

GeneralVisual Localizer Pin
cre8or120-Apr-13 3:46
membercre8or120-Apr-13 3:46 
GeneralRe: Visual Localizer Pin
Ed Gadziemski11-Nov-14 4:47
professionalEd Gadziemski11-Nov-14 4:47 
GeneralMinor bug Pin
Anders Eriksson19-Jan-11 21:57
memberAnders Eriksson19-Jan-11 21:57 
GeneralRe: Minor bug Pin
Jacek Gajek20-Jan-11 8:13
memberJacek Gajek20-Jan-11 8:13 
QuestionWhat about .net localization Pin
Urs Enzler24-Sep-07 23:17
memberUrs Enzler24-Sep-07 23:17 
AnswerRe: What about .net localization Pin
gajatko24-Sep-07 23:54
membergajatko24-Sep-07 23:54 
GeneralExcellent Pin
merlin98120-Sep-07 4:41
membermerlin98120-Sep-07 4:41 
GeneralRe: Excellent Pin
gajatko21-Sep-07 22:00
membergajatko21-Sep-07 22:00 
QuestionWhat about R# + RGreatEx ? Pin
Alexander Nestrenko19-Sep-07 21:23
memberAlexander Nestrenko19-Sep-07 21:23 
AnswerRe: What about R# + RGreatEx ? Pin
gajatko20-Sep-07 1:35
membergajatko20-Sep-07 1:35 
GeneralRe: What about R# + RGreatEx ? Pin
Alexander Nestrenko20-Sep-07 1:47
memberAlexander Nestrenko20-Sep-07 1:47 
GeneralRe: What about R# + RGreatEx ? Pin
Alex Kucherenko14-May-08 7:00
memberAlex Kucherenko14-May-08 7:00 
GeneralRe: What about R# + RGreatEx ? Pin
gajatko14-May-08 10:01
membergajatko14-May-08 10:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 May 2008
Article Copyright 2007 by Jacek Gajek
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid