Soluling home   Document home

Script and Source Code Localization and Internationalization

Script and Source Code Localization and Internationalization

Scripting languages (Wikipedia) are very popular elements of many IT solutions. They are used in web applications, web pages, help files, mobile applications, and even desktop applications. Source code (Wikipedia) is very similar to the scripting language. The biggest difference is that source code is most often compiled when scripts are interpreted. If your code (script or source code) contains hardcoded strings, you should remove them and replace them with resource strings. If your programming environments support resources, you can resource your source code. Unfortunately, most scripting languages do not support resource strings. In that case, you need to localize your script or source code. Soluling localization tool and service support the localization of scripting and programming languages.

Localization Process

The localization process of scripts and source code is the same. Soluling reads original the original file or data, extracts strings, and finally, when building, creates localized files or data. There is one output file or data for each language.

char* Sample()
{
  return "This is a sample";
}

The above sample contains one hardcoded string: "This is a sample." When we localize this into German, the code would be

char* Sample()
{
  return "Das ist ein Beispiel";
}

When we localize this into Japanese, the code would be

char* Sample()
{
  return "これはサンプルです";
}

As you can see, the structure and logic of all three codes are exactly the same. The only difference is the string value. The first has an English value, the second one has German, and the last one has Japanese.

When Soluling parses the code, it extracts the strings and gives the string a context. This context is the same as the value of the string. So our sample code has "This is a sample" string whose context is "This is a sample." Using string value as the context makes Soluling much more robust to handle code changes (your code will be most likely to change when time passes). However, it also brings one important side effect. If you have the same string two or more times in the same code file, Soluling will create only one row for the string. The row is shared between both instances of the string. This makes it impossible to localize the second string in a different way than the first one. If you need to localize them in a different way, you can add one invisible character, such as space, at the end of another string. This will make context value differ and will bring you two rows instead of one. Another solution is to use another context method but a string value. Soluling supports two other methods: index and key value. Use the Options sheet to select the context method.

Programming language

Soluling supports all major programming languages.

Language Extensions Description
Basic/Visual Basic/VBScript .bas, .vb Basic (Wikipedia), Visual Basic (Wikipedia), or VBScript (Wikipedia)
C/C++ .c, .h, .cpp, .hpp C (Wikipedia) or C++ (Wikipedia)
C# .cs C# (Wikipedia)
Go .go Go (Wikipedia)
Groovy .groovy, .gvy, .gy, .gsh Groovy (Wikipedia)
Java .java Java (Wikipedia)
JavaScript/TypeScript .js JavaScript (Wikipedia) or TypeScript (Wikipedia)
Objective-C .m Objective-C (Wikipedia)
Pascal/Delphi .pas, .dpr, .rgs Pascal (Wikipedia), Object Pascal (Wikipedia), or Delphi (Wikipedia)
Perl .pl Perl (Wikipedia)
PHP .php PHP (Wikipedia)
Python .py, .pyw, .pyc, .pyo, .pyd Python (Wikipedia)
Ruby .rb, .rbw, Ruby (Wikipedia)
Scala .scala Scala (Wikipedia)
SQL .sql SQL (Wikipedia)
Swift .swift Swift (Wikipedia)
Custom programming language   A custom programming language. Define the language by specifying strings separators and comment strings.

If your programming language is not on the above list, select Custom programming language and specify the properties of the language. Use the Programming language sheet the select the language.

Tags

Tags are special comments you add to your original source code. The purpose of the tags is to control what strings are localized and how the strings are localized. Tags are mostly used with source code or script files. A tag can also be used to give resource file items some properties such as the maximum length of the string or a regular expression to parse the string.

When a parser reads code, it can handle tags in two modes. They are:

Localize all but exclude tagged strings

Soluling localizes all strings except those that have an exclude tag. Check this if you want to scan most of the strings of your code files. Add the exclude tags after those strings that you don't want to localize. This is the default tag mode in most cases.

void Sample()
{
  char* name = "Ice Hockey";
  char* country = "Canada";
  char* sql = "SELECT * FROM Sample"; //noloc
}

The above code sample contains three strings. The first two should be localized, but the last cone contains a SQL statement and should not be localized. This is why there is an exclude tag (noloc) in a comment on the same line as the string.

Localize only tagged strings

Soluling localizes only those strings that have an include tag. Check this if you want to scan only some of the strings of your code files. Add include tags after those strings that you want to localize.

void Sample()
{
  char* name = "Ice Hockey"; //loc
  char* country = "Canada";  //loc
  char* sql = "SELECT * FROM Sample";
  char* code = "abs125";
  char* file = "C:\\Sample\\Hocket.txt";
  char* teamTag = "team";
  char* playerTag = "player";
}

The above code sample contains several strings. Only the first two should be localized. This is why we should turn on the localize only tagged strings mode and add an include tag (loc) in a comment on the same line as the string we want to localize.

Include/Property tag

Include/Property tag is used to mark string to be localized, and it can also be used to pass some string properties to the project. The syntax is

<comment-mark><tag>[MaxChars=characters][MaxPixels=pixels][Structure="structure"][RegEx="regex"][comment]

where

comment-mark A single line comment mark used in this programming language. For example, C++ and most other languages use "//"
tag A tag string. The default value is loc, but you can modify this by editing the value.
characters The maximum length of the translation in characters.
pixels The maximum length of the translation in pixels.
regex A regular expression that is used to check the validity of the translation. If entered, every translation must match the regular expression.
structure A string sructure that is used to parse the string.
comment Any comment that is passed to the project as the row comment of this string.

The following line has an include tag that makes Soluling scan the string:

str = "Hello world"; //loc

The following line has the same effect:

str = /*loc*/ "Hello world";

The following line has a property tag that contains a comment ("Clicking this button opens on-line help") and sets the maximum length to 200 pixels:

str = "Length of the area"; //loc MaxPixels=200 Length of the cutting area in centimeters

Properties in the tag comment can be at any order. The case of the property names is case insensitive. The following is the same as the above.

str = "Length of the area"; //loc Length of the cutting area in centimeters maxpixels=200 

Exclude tag

If you don't want to localize a string, add an exclude tag on the same line where the string is located. The syntax is

<comment-mark><tag>

For example, the following line contains a SQL statement, and it should not be localized. To disable the localization, add a following exclude tag:

str = "SELECT * FROM Sample"; //noloc

Block exclude tag

You can disable localization of an entire source code block by using block exclude tags. There are two tags: start and end tags. The localization of all lines between these two tags is disabled. The syntax is

<comment-mark><begintag>
line1
line2
...
<comment-mark><endtag>

For example, the two strings in the following lines are not localized.

// beginnoloc
a = "Do not localize";
b = "Same for this";
// endnoloc

Editing

Use the Tags sheet of the Source dialog to edit tagging properties.

Samples

GitHub and <data-dir>\Samples\SourceCode contains following source code samples:

Directory Description
Simple A simple C++ source code that contains only one string.
Exclude A C++ source code that uses the exclude tags. Soluling localizes all strings except thos that have an exclude tagged.
Include A C++ source code that uses the include tags. Soluling localizes only those strings that have been tagged.
Tags A C++ source code that uses various tags to control localization.

In addition to the above samples following samples show script localization:

Directory Description
<data-dir>\​Samples\ASP.NET All ASP.NET samples use script localization.
<data-dir>\​Samples\HTML\Script  
<data-dir>\​Samples\HtmlHelp\SportRoboHelp  
<data-dir>\​Samples\JSP All JSP samples use script localization.
<data-dir>\​Samples\PHP All PHP samples use script localization.
<data-dir>\​Samples\SVG\Script  

Configuring Script and Source Code Properies

You can configure how to localize your script or source code file by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.