Raku: la lingua dove posso parlare italiano

(Raku: the language where I can speak Italian)

There are a few interesting modules in the L10N namespace in the Raku ecosystem: L10N itself and the family of L10N::... modules written by different authors (I added three just yesterday).

What these modules allow you to do is switch the built-in keyword dictionary of the language itself and thus write code in a language other than English.

Of course, you could always use identifiers (such as variable and routine names) in any language, including those with non-Latin alphabets.

my $saluto = 'Buongiorno';
my $nome = 'Isabella';
say "$saluto, $nome!";

But these modules allow you to extend the idea to elements of Raku itself. Consider the following program:

il-mio $saluto = 'Buongiorno';
il-mio $nome = 'Isabella';
dillo "$saluto, $nome!";

This program does not compile unless you add L10N::IT:

use L10N::IT;

il-mio $saluto = 'Buongiorno';
il-mio $nome = 'Isabella';
dillo "$saluto, $nome!";

And voilà (ok, that’s for L10N::FR), you get the result:

% raku test.raku
Buongiorno, Isabella!

As of today, there are a bit over a dozen different localisation modules in the Raku ecosystem.

(To run the program with Rakudo prior to its version 2026.09, set RAKUDO_RAKUAST=1.)

Mechanics

If you’d like to contribute a missing language, consult the L10N documentation first to get an idea of how to generate the module template so that it fits the rest of the family.

A concrete module is generated from a simple text file containing a list of pairs: a regular Raku keyword, e.g., my, and its translation: il-mio or mijn. By the way, that my can be translated into more than one word depending on the gender, as, for example, in Latvian: mans, mana, as well as plural mani or manas, but such support of synonyms is not yet fully used, as I can tell.

Using a module attaches a role to the Raku grammar, which lists the keyword tokens in their translated forms. For example, here is a small extract from the Latvian grammar for the two keywords: my and our:

role L10N::LV {
    . . .
    token scope-my { mans }
    token scope-our { mūsu }
    . . .
}

In the other direction

All these modules share the same design pattern, so you may expect that you can translate the source code back to English. The localisation generator creates yet another role, e.g. RakuAST::Deparse::L10N::LV.

It contains a long list of keywords for reverse translation:

my constant %xlation = . . . 
    "scope-my", "mans", "scope-our", "mūsu", . . .

Call the .DEPARSE method on the .AST (so at this point you indirectly touched on two features of Raku: slangs and RakuAST) and get back to English:

% raku -ML10N::IT
Raku++ 3.28.0 — \h for help, ^D to exit

> 'test.raku'.IO.slurp.AST('IT').DEPARSE

my $saluto = "Buongiorno";
my $nome = "Isabella";
say "{$saluto}, {$nome}!" 

And that’s all for now: short text, but what’s described in this blog post opens up the whole internal Universe of Raku.

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code