Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@gradeup/i18n-abide
Advanced tools
This module abides by the user's language preferences and makes it available throughout the app.
This module abides by the Mozilla L10n way of doing things.
The module abides.
Used in production systems, such as the Mozilla Persona service in 40+ languages.
Also used on other websites including:
This module supports several localization backends:
This module supports client side as well as server side localization.
npm install i18n-abide
In this README, we'll use express and EJS templates, but other integrations are possible.
In your app where you setup express:
var i18n = require('i18n-abide');
app.use(i18n.abide({
supported_languages: ['en-US', 'de', 'es', 'db-LB', 'it-CH'],
default_lang: 'en-US',
debug_lang: 'it-CH',
translation_directory: 'i18n'
}));
This block sets up the middleware and views with gettext support. We declare support for English, German, Spanish, and two debug locales (more on this later).
In your routes, you can use the gettext function in .js
files.
exports.homepage = function(req, resp) {
resp.render('home', {title: req.gettext("Hey, careful, man, there's a beverage here!")});
};
In your layout files, you can add
<!DOCTYPE html>
<html lang="<%= lang %>" dir="<%= lang_dir %>">
<head>
<meta charset="utf-8">
...
In your templates files, you can use the gettext function in .ejs
files:
<p><%= gettext("This will not stand, ya know, this aggression will not stand, man.") %></p>
i18n-abide also provides a format
function for string interpolation.
This module provides both server side translations and client side translations. Server side works out of the box and is the most common use case.
If you also want to do client-side translations,
i18n-abide provides lib/gettext.js
and you can do the same in .js
and
.ejs
files.
The i18n-abide
module uses the
accept-language
HTTP header
to determine which language to use.
See API docs for overriding this via URL or the API directly.
The i18n-abide
module currently supports three file formats.
PO/POT files, which get transformed to JSON via provided command line tools.
PLIST (i.e., XML) files, which require no transformation prior to use.
Transifex JSON (JavaScript Object Notation) a key-value JSON type, which require no transformation prior to use.
This is the default and assumed for documentation in this README.
PO files can be compiled to .json or Gettext binary .mo
files.
For use on the client side, PO files are compiled to JavaScript for easy inclusion into your page or build script.
NOTE: The PO/POT files are also transformed into .JSON, but do not follow the same layout as the Transifex JSON files.
See GETTEXT.md for more details.
See API for configuration and details around using Plist or Transifex localization files.
db-LB
is a special debug locale.
To trigger it, set your Browser or Operating System language to Italian
(Switzerland) which is it-CH
.
This fake locale db-LB
will be triggered,
it is David Bowie speak for the region of Labyrinth.
Oh, hell ya a "The Dude" / Bowie Mashup. That just happened.
Now, start up your Node server and visit a page you've wrapped strings in Gettext...
Mozilla Hacks blog has a three part introduction.
FAQs
Express/connect module for Node i18n and l10n support
The npm package @gradeup/i18n-abide receives a total of 0 weekly downloads. As such, @gradeup/i18n-abide popularity was classified as not popular.
We found that @gradeup/i18n-abide demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.