Templotar : CastleDB localization

03.24.2014 8104 0

CastleDB is a static database written wy Nicolas Cannasse that uses a JSON file to store data and comes with a Haxe library and a simple editor.

You can store different kind of data and retrieve them in the Haxe context, CastleDB comes also with some magic macro, but I use it here simply to store some static texts that I use for my templates and manage language localization.

And to manage all that, from templating with templo for example to translation, here's a little tool, as usual .


Templating

Let's say we have 2 templo templates like that :

// shell.mtt
<html>
	<head>
		<title>My Website</title>
	</head>
	<body>
		<ul class="menu">
			<li><a href="#">News</a></li>
			<li><a href="#">Movies</a></li>
			<li><a href="#">Connect</a></li>
		</div>
		<div class="content">::raw __content__::</div>
		<div id="footer">
			<p>All rights reserved</p>
		</div>
	</body>
</html>
// news.mtt
::use 'shell.mtt'::
<h1>News</h1>
<div class="news">
	<p>Here are the news !</p>
</div>
::end::

You build all your website in your favourite language.

Start translation

In order to begin the translation step, you have to surround all the words and sentences in all your favourite language templates with a token, let's say it's "@@" by default (but you can choose your own which is probably better )

So the templates files look like that now :

// shell.mtt
<html>
	<head>
		<title>@@My Website@@</title>
	</head>
	<body>
		<ul class="menu">
			<li><a href="#">@@News@@</a></li>
			<li><a href="#">@@Movies@@</a></li>
			<li><a href="#">@@Connect@@</a></li>
		</div>
		<div class="content">::raw __content__::</div>
		<div id="footer">
			<p>@@All rights reserved@@</p>
		</div>
	</body>
</html>
// news.mtt
::use 'shell.mtt'::
<h1>@@News@@</h1>
<div class="news">
	<p>@@Here are the news !@@</p>
</div>
::end::

These new templates will be the "generic" ones.

Templotar

It's a light command-line tool that will :

  • Write the wanted languages templates filled by defaut with the favourite language
  • Write a .cdb (CastleDB) file, to use for translation (see below)
  • Rewrite the wanted languages templates filled with the new .cdb file containing entire or partial translation (and so on...)

How to use it

Usage : Templotar <file> <file>...<file> [options]
Options :
 -o <path> : Set output directory (default : current directory/out)
 -i <path> : Set input directory (default : current directory)
 -l <ln>,<ln>,...<ln> : Set output languages (default : fr)
 -cdb <file> : Try to get indexes and translation from this file
 -t <string> : Token used (default : @@)
 -rg : Rewrite generics agains preferrred language
 -v  : Verbose

Let's translate the generic templates into english (the favourite language here) and french :

Templotar -i generic shell.mtt news.mtt -o . -l en,fr

Now we have got 2 new folders "en" and "fr" with each the english, favourite words and sentences.
In the output folder there is also a new "texts.cdb" file. If you open it with CastleDB, you'll see something like that :

Only unique ids are kept : News are used twice but written only once.
As seen before, the "fr" sheet is filled by default with english.

When a word or a sentence is translated in the .cdb file like that :

The next command is the same as before with an additional option :"-cdb" which will take the .cdb file with the new translation as input :

Templotar -i generic shell.mtt news.mtt -o . -l en,fr -cdb texts.cdb

Now we get also 2 folders, "en" and "fr", but now, in the "fr" template the word "News" is translated. Other words and sentances are the default ones :

// shell.mtt
<html>
	<head>
		<title>My Website</title>
	</head>
	<body>
		<ul class="menu">
			<li><a href="#">Actualités</a></li>
			<li><a href="#">Movies</a></li>
			<li><a href="#">Connect</a></li>
		</div>
		<div class="content">::raw __content__::</div>
		<div id="footer">
			<p>All rights reserved</p>
		</div>
	</body>
</html>
// news.mtt
::use 'shell.mtt'::
<h1>Actualités</h1>
<div class="news">
	<p>Here are the news !</p>
</div>
::end::

This operation can be done and redone as many time as needed, as a new translation is done...until all is translated :

Download

Templotar is written in Haxe and runs under the nekoVM.
You can download it here.

Comments

Write a comment

http://
×