Re: Localization in Dada Mail

 
From: "Moshe Katz" <kohenkatz@PROTECTED>
Date: February 7th 2010
I may be able to do Hebrew, assuming Right-to-Left is supported.

------------------------------
Moshe Katz
KatzNet Computers
-- kohenkatz@PROTECTED
-- +1(301)867-3732


On Sun, Feb 7, 2010 at 1:26 AM, Justin J <justin@PROTECTED> wrote:

I've been working on the problem of localization in Dada Mail.

What makes this an interesting project within Dada Mail is because:

* This is becoming the #1 requested feature: "Is this available in my language?"

And I keep having to say, "no, but..." and then tell them to go through all the templates and manually edit them. This makes people go, "well, what happens when I upgrade?" And, I have no good answer to that. And that sucks.

* What a great way to get more people involved in Dada Mail

And this will happen two ways:

#1 For this project to work, people will need to do the language translations. I can't do every darn language :) It would be great to have English, French, German and Spanish to start out.

I *do* want to take a stab at the French translation, since that's my personal second language that I'm currently studying actively. I *think* other people, even on this list, would be interested in other language translations. These translations can also be collaborative, since we live in a world of version control systems ;)

#2 More people will use Dada Mail, since it'll be localized to their language, etc. This is a great thing, since more users means a more healthier project, as far as I'm concerned.

I've been doing a lot of research on how to pull this off. There's a lot of problems:

* There's text that needs to be translated in Dada Mail that lives in template files and in the source of the program itself. There will always be these two things.

No one - not one person, wants to slog through every file in Dada Mail, looking for text to translate.

* Then, there's the upgrade problem. Woo - boy, how do you handle when the program gets upgraded? All the translated work has to be thrown out?
* Text needs to be in one central place (for each language) that can be easily edited by *non programmers* to be able to edit
* How do you do this, without needing a gigantic dependency tree?

A lot of what makes Dada Mail popular is that you don't have to install CPAN Perl modules yourself to get up and running. This has to be true for anything new installed, dealing with localization.


I've finally gotten around to figuring out how to pull all these things together.

What I propose to use is a module called: Locale::Maketext::Lexicon

       http://search.cpan.org/dist/Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm

This module has a lot of neat features.

One of them is, there's no real nasty dependencies - it's in Perl core, itself. The few things that aren't already in the core Perl distro, I can easily bundle myself. It hasn't been updated in about a year, so it's not exactly a fast-moving target

The way it works is this:

It has the idea of something called, ".po" files. In it, there are key/value entries for all the strings you want/need to translate. The key has the original text in the original language, the value is what your translation will be. For example, here is a key/value pair in a .po file:

msgid "Hello, World!"
msgstr "Bonjour, tout le monde!"


This is in a .po file for the English -> French translation.

These key/value pairs can do some pretty fancy things (but still be fairly readable), if you have to deal with localization thingies, like dates, times, numbers - stuff like that.


I've made a simple program to illustrate all this - you can download it here:

       http://dadamailproject.com/dev/local.tar.gz

Here's the directory structure - if you'd like to download and walk along with me:

local
 hello.pl
 lang
   hello_fr.po
 MyProgram
   Config.pm
   L10N.pm
 tmpls
   hello.tmpl

"hello.pl" is our program. It's going to parse and print out the template in, "tmpls/hello.tmpl". It has strings in English, that we're going to have translate into French. Looks like this:

       <html>
       <head><title>{{Hello}}!</title>
       <body>
       <p><!-- tmpl_var greeting --></p>
       <p>
               {{My name is Justin! It's very nice to meet you!}}
       </p>

       </body>
       </html>

See those double-braces? That's the little signifier used to tell this little program that within these, are strings that should be translated. There's also going to be another variable we're going to pass to the template, <!-- tmpl_var greeting --> that we're going to have translated in the program, itself.

Every single template file will need to have these double-braces applied to the strings we want translated, but it's not that scary.

The program has a config module (just like Dada Mail). All it does is set the language. In, MyProgram/Config.pm, you'll see the line:

       $lang = 'fr';

That tells it to use French.

All the fancy-footwork that does the localization is in the, MyProgram/L10N.pm file. It's not too scary.

In the, hello.pl this takes care of the localization:

use MyProgram::L10N;
my $lh = MyProgram::L10N->get_handle($MyProgram::Config::lang)
 || die "What language?";

Once you have that, "$lh" object, you can change simple, "print" statements, like:

print "Hello, World!";

to,

print $lh->maketext("Hello, World!");

and the French localization will happen! That's it and that's how inline translation in perl code will work. You won't need to hunt for this yourself. It'll be a little grudgework to get that all set in Dada Mail, but it's not really that difficult.



And here's the big problem - especially for something so large and organically grown as Dada Mail -

How do we *find* all these strings that need translated?


Well,

Local::Maketext::Lexicon has a nifty utility:

       http://search.cpan.org/~drtech/Locale-Maketext-Lexicon/script/xgettext.pl

That does just that.

If you run it on the, "local" directory:

justin$ xgettext.pl -D ./local

It'll give you a, ".po" file, that'll have this as the contents:


#: local/tmpls/hello.tmpl:2
msgid "Hello"
msgstr ""

#: local/hello.pl:13
msgid "Hello, World!"
msgstr ""

#: local/tmpls/hello.tmpl:6
msgid "My name is Justin! It's very nice to meet you!"
msgstr ""

All I need to do, is fill in the translations that are in the, "msgid" thingies, and put them in the, "msgstr" thingies. For French, it would look a little like this:



#: tmpls/hello.tmpl:2
msgid "Hello"
msgstr "Bonjour"

#: hello.pl:13
msgid "Hello, World!"
msgstr "Bonjour, tout le monde!"

#: tmpls/hello.tmpl:6
msgid "My name is Justin! It's very nice to meet you!"
msgstr "Je m'appelle Justin! C'est trés gentil vous connâitre!"


Now, here's the kicker - you can update this file (say, when you make changes - big changes, to the program), using the same utility! Woo!


This system will also work for partially translated stuff - it won't blow up if there's a missing key/value pair. Nice.

So, if you run the script, with English inline and within the template file, but with the program set to localize into French (and with a English -> French .po file), it'll output:



<html>
<head><title>Bonjour!</title>
<body>
<p>Bonjour, tout le monde!</p>
<p>
       Je m'appelle Justin! C'est trés gentil vous connâitre!
</p>

</body>
</html>

Pretty much exactly what we need.



Here's some further reading:

Locale::Maketext::TPJ13 -- article about software localization

http://search.cpan.org/~ferreira/Locale-Maketext-1.13/lib/Locale/Maketext/TPJ13.pod


Web Localization in Perl
http://cpansearch.perl.org/src/DRTECH/Locale-Maketext-Lexicon-0.77/docs/webl10n.html

You don't have to know this - I barely understand it, and the people doing the translating definitely DO NOT need to know how this is implemented. All they have to do, is to fill out the translations of the strings in those .po files - and those .po files are made automatically.



So, can I "sign up" anyone that wants a language? :) Like I said, collaboration on the same language is def. possible. If you know github, it'd be the best to fork your own copy of Dada Mail and get hacking.

BEFORE you do that, I need to put all the localization code in Dada Mail, change the strings so that the localization works (and can be found by the automatic find thingy) and normalize some of the strings, so that translation is easier - and probably make the French localization to use as a guide.


Let me know if this sounds like something you can help on ;)


--
Justin J.

Dada Mail -  Write Once: Distribute Everywhere Software
url: http://dadamailproject.com

The Dada Mail Demo:
http://demo.dadamailproject.com



--

Post:
<mailto:dadadev@PROTECTED>

Unsubscribe:
<http://dadamailproject.com/cgi-bin/dada/mail.cgi/u/dadadev/>

List Information:
<http://dadamailproject.com/cgi-bin/dada/mail.cgi/list/dadadev>

Archive:
<http://dadamailproject.com/cgi-bin/dada/mail.cgi/archive/dadadev>

Mailing List Powered by Dada Mail
http://dadamailproject.com/cgi-bin/dada/mail.cgi/what_is_dada_mail/=

Post:
mailto:[list_settings.discussion_pop_email]

Unsubscribe:
http://dadamailproject.com/cgi-bin/dada/mail.cgi/u/dadadev/

List Information:
[PROGRAM_URL]/list/[list_settings.list]

Archive:
[PROGRAM_URL]/archive/[list_settings.list]

Mailing List Powered by Dada Mail

  • This mailing list is a public mailing list - anyone may join or leave, at any time.
  • This mailing list is a group discussion list (unmoderated)
  • Start a new thread, email: dadadev@dadamailproject.com

This is the developer discussion mailing list for Dada Mail.

If you are just looking for support Dada Mail, consult the message boards at:

https://forum.dadamailproject.com

Documentation for Dada Mail:

https://dadamailproject.com/d

Specifically, see the Error FAQ:

https://dadamailproject.com/d/FAQ-errors.pod.html

To post to this list, send a message to:

mailto:dadadev@dadamailproject.com

All subscribers of this list may post to the list itself.

Topics that are welcome:

  • Constructive critiques on the program (I like, "x", but, "y" needs some work - here's an idea on how to make this better...)
  • Bug/Error reports
  • Bug fixes
  • Request For Comments on any changes to the program
  • Help customizing Dada Mail for your own needs
  • Patches
  • Language Translations
  • Support Documentation/Doc editing, FAQ's, etc.
  • Discussion of any changes that you would like to be committed to the next version of Dada Mail -

Dada Mail is on Github:

https://github.com/justingit/dada-mail/

If you would like to fork, branch, send over PRs, open up issues, etc.

Privacy Policy:

This Privacy Policy is for this mailing list, and this mailing list only.

Email addresses collection through this mailing list are used explicitly to work within this email discussion list.

We only collect email addresses through our Closed-Loop Opt-In system.

We don't use your email address for any other purpose.

We won't be sharing your email address with any other entity.

Unsubscription can be done at any time. Please contact us at: justin@dadamailproject.com for any help regarding your subscription, including removal from the mailing list.

All mailing list messages sent from us will include a subscription removal link, which will allow you to remove yourself from this mailing list automatically, and permanently.

All consent to use your email address for any other purpose stated at the time of the mailing list subscription will also be revoked upon mailing list removal.