Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
gettext-translator
Advanced tools
Readme
Javascript gettext translations replacement to use with gettext/gettext. Use gettext/json to generate the json data.
npm install gettext-translator
Use the Json generator gettext/json library to export the translations to json:
use Gettext\Loader\PoLoader;
use Gettext\Generator\JsonGenerator;
//Load the po file with the translations
$translations = (new PoLoader())->loadFile('locales/gl.po');
//Export to a json file
(new JsonGenerator())->generateFile('locales/gl.json');
Load the json file in your browser
import Translator from 'gettext-translator';
async function getTranslator() {
const response = await fetch('locales/gl.json');
const translations = await response.json();
return new Translator(translations);
}
const t = await getTranslator();
t.gettext('hello world'); //ola mundo
You can add variables to the translations. For example:
t.gettext('hello :who', {':who': 'world'}); //ola world
There's also a basic support o sprintf (only %s
and %d
)
t.gettext('hello %s', 'world'); //ola world
To customize the translator formatter, just override the format
method:
t.format = function (text, ...args) {
//Your custom format here
}
Like in the php version, there are the __
functions that are alias of the long version:
//Both functions does the same
t.gettext('Foo');
t.__('Foo');
Long name | Short name | Description |
---|---|---|
gettext | __ | Returns a translation |
ngettext | n__ | Returns a translation with singular/plural variations |
dngettext | dn__ | Returns a translation with domain and singular/plural variations |
npgettext | np__ | Returns a translation with context and singular/plural variations |
pgettext | p__ | Returns a translation with a specific context |
dgettext | d__ | Returns a translation with a specific domain |
dpgettext | dp__ | Returns a translation with a specific domain and context |
dnpgettext | dnp__ | Returns a translation with a specific domain, context and singular/plural variations |
FAQs
Javascript gettext translator
The npm package gettext-translator receives a total of 981 weekly downloads. As such, gettext-translator popularity was classified as not popular.
We found that gettext-translator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.