Locale:...aScript(3)
π 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
languageattribute, 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::ConstantsLocale::TextDomain::OO::Util::JoinSplitLexiconKeysLocale::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. π
π LICENSE AND COPYRIGHT π
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
- fedora 43: perl-Locale-TextDomain-OO 1.036-19.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms