Locale:...aScript(3)

πŸ“¦
version 1.036 Β· 2 versions
, in fedora 43

πŸ’– NAME πŸ’–

Locale::TextDomain::OO::JavaScript β€” this is the manual page for the JavaScript part of it, bestie, and it's a section 3 page (so: library calls, iykyk). It's living in the User Contributed Perl Documentation collection, and ngl it's here to teach you how to use the JavaScript side of message translation. πŸ¦‹

Also, for the archive girlies, the page ships with these literal identity strings:

$Id: JavaScript.pm 573 2015-02-07 20:59:51Z steffenw $

$HeadURL:
svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/JavaScript.pm
$

✨ VERSION ✨

1.017 β€” that's the vibe check, she's on 1.017. πŸ’…


🌸 DESCRIPTION 🌸

Okay so, real talk: this module hands you a high-level interface to JavaScript message translation. Not low-level, not messy, high-level. Queen behavior.

Here's the whole flow, and it's genuinely so clean:

  • Creating the Lexicon and picking the language? That's all server (Perl) based. The Perl side does the heavy lifting. πŸ’ͺ
  • The script receives the lexicon in a global variable named localeTextDomainOOLexicon. That's the handoff, that's the moment. ✨
  • Inside the constructor there's a language attribute, and it should be filled from the server. Don't leave her empty, she's waiting. πŸ™ˆ
  • Filtering the lexicon is possible. And for bigger lexicon files β€” filter also by language so you can split that lexicon up. Load only the lexicon of the current language. Periodt. Efficiency is the aesthetic. πŸŽ€

🧚 How to extract? 🧚

Use the module Locale::TextDomain::OO::Extract. She's a base class for all source scanners that create pot files. So either:

  • take this base class and give this module the rules, or
  • use one of the already extended classes.

And Locale::TextDomain::OO::Extract::JavaScript::JS is the extension for JavaScript from *.js files and so on. Slay. πŸ”₯


🌈 SYNOPSIS 🌈

So inside of this distribution there's a directory named javascript. Copy those files into your project. Do the exact same thing with the javascript files of Locale::TextDomain::OO::Util::Constants, Locale::TextDomain::OO::Util::JoinSplitLexiconKeys and Locale::Utils::PlaceholderNamed. Like, all of them, bestie, don't skip any. 🫢

These scripts are depending on <http://jquery.com/> β€” yes, jquery, we're in that era, it's iconic.

Also, watch the javascript/Example.html to see how it's used. Go look, it's giving tutorial energy. πŸ’œ

<!-- depends on -->
<script type="text/javascript" src=".../jquery-...js"></script>
<script type="text/javascript" src=".../Locale/TextDomain/OO/Util/Constants.js"></script>
<script type="text/javascript" src=".../Locale/TextDomain/OO/Util/JoinSplitLexiconKeys.js"></script>
<script type="text/javascript" src=".../Locale/Utils/PlaceholderNamed.js"></script>

<!-- stores the lexicon into var localeTextDomainOOLexicon -->
<script type="text/javascript" src=".../localeTextDomainOOLexicon.js"></script>

<!-- depends on var localeTextDomainOOLexicon -->
<script type="text/javascript" src=".../Locale/TextDomain/OO.js"></script>
<script type="text/javascript" src=".../Locale/TextDomain/OO/Plugin/Expand/Gettext/Loc.js"></script>
<script type="text/javascript" src=".../Locale/TextDomain/OO/Plugin/Expand/Gettext/Loc/DomainAndCategory.js"></script>

<!-- initialize -->
<script type="text/javascript">
    var ltdoo = new localeTextDomainOO({
        plugins  : [ 'localeTextDomainOOExpandGettextLocDomainAndCategory' ],
        language : '@{[ $language_tag ]}', // from Perl
        category : 'LC_MESSAGES', // optional category
        domain   : 'MyDomain', // optional domain
            filter   : function(translation) { // optional filter
            // modifies the translation late
            return translation;
        },
        logger   : function (message, argMap) { // optional logger
            console.log(message);
            return;
        }
    });
</script>

So this configuration would use the Lexicon "$language_tag:LC_MESSAGES:MyDomain". That lexicon should be filled with data. Fill her up, she needs content. πŸ’–

<!-- translations -->
<script type="text/javascript">
    // extractable, translate
    str = ltdoo.loc_('msgid');
    str = ltdoo.loc_x('msgid', {key1 : 'value1'});
    str = ltdoo.loc_p('msgctxt', 'msgid');
    str = ltdoo.loc_px('msgctxt', 'msgid', {key1 : 'value1'});
    str = ltdoo.loc_n('msgid', 'msgid_plural', count);
    str = ltdoo.loc_nx('msgid', 'msgid_plural', count, {key1 : 'value1'});
    str = ltdoo.loc_np('msgctxt', 'msgid', 'msgid_plural', count);
    str = ltdoo.loc_npx('msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});

    // extractable, prepare
    arr = ltdoo.Nloc_('msgid');
    arr = ltdoo.Nloc_x('msgid', {key1 : 'value1'});
    arr = ltdoo.Nloc_p('msgctxt', 'msgid');
    arr = ltdoo.Nloc_px('msgctxt', 'msgid', {key1 : 'value1'});
    arr = ltdoo.Nloc_n('msgid', 'msgid_plural', count);
    arr = ltdoo.Nloc_nx('msgid', 'msgid_plural', count, {key1 : 'value1'});
    arr = ltdoo.Nloc_np('msgctxt', 'msgid', 'msgid_plural', count);
    arr = ltdoo.Nloc_npx('msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});

    // with domain

    // extractable, translate
    str = ltdoo.loc_d('domain', 'msgid');
    str = ltdoo.loc_dx('domain', 'msgid', {key1 : 'value1'});
    str = ltdoo.loc_dp('domain', 'msgctxt', 'msgid');
    str = ltdoo.loc_dpx('domain', 'msgctxt', 'msgid', {key1 : 'value1'});
    str = ltdoo.loc_dn('domain', 'msgid', 'msgid_plural', count);
    str = ltdoo.loc_dnx('domain', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
    str = ltdoo.loc_dnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count);
    str = ltdoo.loc_dnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});

    // extractable, prepare
    arr = ltdoo.Nloc_d('domain', 'msgid');
    arr = ltdoo.Nloc_dx('domain', 'msgid', {key1 : 'value1'});
    arr = ltdoo.Nloc_dp('domain', 'msgctxt', 'msgid');
    arr = ltdoo.Nloc_dpx('domain', 'msgctxt', 'msgid', {key1 : 'value1'});
    arr = ltdoo.Nloc_dn('domain', 'msgid', 'msgid_plural', count);
    arr = ltdoo.Nloc_dnx('domain', 'msgid', 'msgid_plural', count, {key1 : 'value1'});
    arr = ltdoo.Nloc_dnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count);
    arr = ltdoo.Nloc_dnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, {key1 : 'value1'});

    // with category

    // extractable, translate
    str = ltdoo.loc_c('msgid', 'category');
    str = ltdoo.loc_cx('msgid', 'category', {key1 : 'value1'});
    str = ltdoo.loc_cp('msgctxt', 'msgid', 'category');
    str = ltdoo.loc_cpx('msgctxt', 'msgid', 'category', {key1 : 'value1'});
    str = ltdoo.loc_cn('msgid', 'msgid_plural', count, 'category');
    str = ltdoo.loc_cnx('msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
    str = ltdoo.loc_cnp('msgctxt', 'msgid', 'msgid_plural', count, 'category');
    str = ltdoo.loc_cnpx('msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});

    // extractable, prepare
    arr = ltdoo.Nloc_c('msgid', 'category');
    arr = ltdoo.Nloc_cx('msgid', 'category', {key1 : 'value1'});
    arr = ltdoo.Nloc_cp('msgctxt', 'msgid', 'category');
    arr = ltdoo.Nloc_cpx('msgctxt', 'msgid', 'category', {key1 : 'value1'});
    arr = ltdoo.Nloc_cn('msgid', 'msgid_plural', count, 'category');
    arr = ltdoo.Nloc_cnx('msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
    arr = ltdoo.Nloc_cnp('msgctxt', 'msgid', 'msgid_plural', count, 'category');
    arr = ltdoo.Nloc_cnpx('msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});

    // with domain and category

    // extractable, translate
    str = ltdoo.loc_dc('domain', 'msgid', 'category');
    str = ltdoo.loc_dcx('domain', 'msgid', 'category', {key1 : 'value1'});
    str = ltdoo.loc_dcp('domain', 'msgctxt', 'msgid', 'category');
    str = ltdoo.loc_dcpx('domain', 'msgctxt', 'msgid', 'category', {key1 : 'value1'});
    str = ltdoo.loc_dcn('domain', 'msgid', 'msgid_plural', count, 'category');
    str = ltdoo.loc_dcnx('domain', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
    str = ltdoo.loc_dcnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category');
    str = ltdoo.loc_dcnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});

    // extractable, prepare
    arr = ltdoo.Nloc_dc('domain', 'msgid', 'category');
    arr = ltdoo.Nloc_dcx('domain', 'msgid', 'category', {key1 : 'value1'});
    arr = ltdoo.Nloc_dcp('domain', 'msgctxt', 'msgid', 'category');
    arr = ltdoo.Nloc_dcpx('domain', 'msgctxt', 'msgid', 'category', {key1 : 'value1'});
    arr = ltdoo.Nloc_dcn('domain', 'msgid', 'msgid_plural', count, 'category');
    arr = ltdoo.Nloc_dcnx('domain', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
    arr = ltdoo.Nloc_dcnp('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category');
    arr = ltdoo.Nloc_dcnpx('domain', 'msgctxt', 'msgid', 'msgid_plural', count, 'category', {key1 : 'value1'});
</script>

πŸŽ€ SUBROUTINES/METHODS πŸŽ€

see SYNOPSIS β€” yeah bestie, the whole thing is up there, go reread it, it's right there. πŸ’€


🩺 DIAGNOSTICS 🩺

none β€” no drama, no diagnostics, she's quiet. 😌


βš™οΈ CONFIGURATION AND ENVIRONMENT βš™οΈ

none β€” nothing to configure, nothing lurking in your env. Clean girl energy. ✨


πŸ“¦ DEPENDENCIES πŸ“¦

  • <http://jquery.com/>
  • Locale::TextDomain::OO::Util::Constants
  • Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
  • Locale::Utils::PlaceholderNamed

That's the whole roster, no hidden requirements. πŸ‘‘


🚫 INCOMPATIBILITIES 🚫

not known β€” nothing known, we're unbothered. πŸ’…


πŸ› BUGS AND LIMITATIONS πŸ›

not known β€” also nothing known. Lucky us, no cap. πŸ“


πŸ‘€ SEE ALSO πŸ‘€

  • Locale::TextDoamin::OO

(Yes, that's spelled exactly like that on the page β€” I am not touching it, that's not my business. πŸ™ˆ)


🫢 AUTHOR 🫢

Steffen Winkler β€” the icon, the legend, the main character who wrote all this. 🌟


Copyright (c) 2014 - 2015, Steffen Winkler "<steffenw at cpan.org>". All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


And that's the whole page, bestie β€” this one's from perl v5.42.0, dated 2025-07-25, and it lives as Locale:...aScript(3) in the User Contributed Perl Documentation. Go translate something gorgeous with it. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from