Locale-TextDomain-OO - What's going on?‎

Originally as extension

Problems

Break

Taken over goals partially

What's new

What's new

Architecture

https://metacpan.org/pod/Locale::TextDomain::OO#Overview

Architecture lexicon

Architecture translator

recommended plugin

Getext

    ...->loc_('This is a text.');

Gettext with plural, context and placeholder

    ...->loc_npx(
        'appointment', # context
        'This is {dates :num} date.',   # singular
        'This are {dates :num} dates.', # plural
        1, # plural selection
        dates => 1, # placeholder replacement
    );

Maketext

    ...->loc_m(
        'Send email to <strong>[_1]</strong>.',
        #                      ^^^^
        'Max Mustermann <mustermann@example.com>',
    );

With Maketext, you can not give the placeholder attribute ":html".

Maketext and context

    ...->loc_mp(
        'appointment', # context
        'This are [*,_1,date,dates].',
        #     ^^^
        1, # plural selection and placeholder replacement
    );

At Maketext plural is limited.

HTML and JavaScript

HTML is also translatable. But it's 2nd choice to plain text.

JavaScript is also translated.

    ...->loc_('... <a href="foo.de" on...="...">...</a> ...');

There is a risk to destroy HTML and JavaScript during translation.

not exist - not wrong

HTML is unlikely broken, because primitive. JavaScript does not break.

The solution here is HTML::Zoom and an empty a tag, because it is configured only during rendering. (Patrick Grämer)

    <span class="...">... <a>...</a> ...</span>

... and then insert the final link

    ->replace_content( \$ctx->loc_('<a>...</a>') )
    ->then
    ->collect({
        filter => sub {
            $_
                ->select('a')
                ->set_attribute('href' => 'foo.de');
        },
        passthrough => 1,
    })

JavaScript Initialisation

<script type="text/javascript">
    var language_locales = {
        "LC_NUMERIC":{
            "decimal_point":".", "thousands_sep":",", "grouping":["3","3"]
        },
        "LC_MONETARY":{
            "n_sep_by_space":"0", "currency_symbol":"£", "p_sign_posn":"1", "negative_sign":"-", "int_curr_symbol":"GBP ", "frac_digits":"2", "p_sep_by_space":"0", "positive_sign":"", "n_cs_precedes":"1", "p_cs_precedes":"1", "int_frac_digits":"2", "mon_grouping":["3","3"], "n_sign_posn":"1", "mon_thousands_sep":",", "mon_decimal_point":"."}
        };
    var language_tag = "i-default";
    $(function() {
        $.datepicker.setDefaults($.datepicker.regional['en-GB']);

Extract

Locale::TextDomain::OO::Extract

Process

Locale::TextDomain::OO::Process

https://metacpan.org/.../example/21_process_utf-8.pl

The example says all about the process. When working with MO files, you must still run at the end:

    $process->spew(mo => "../2nd_${language}_${domain}_clean.mo");

Autotranslator 1/2

Locale::Utils::Autotranslator

Autotranslator 2/2

Locale::Utils::Autotranslator

https://metacpan.org/.../example/01_my_translator_utf-8.pl

The example also shows how the placeholders pass the translation tool.

End