New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gettext-translator

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gettext-translator

Javascript gettext translator

  • 2.0.1
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Gettext translator

Javascript gettext translator. Use gettext/gettext PHP library to generate and modify the messages.

Supports:

  • AMD
  • CommonJS
  • Global js

Installation

npm install gettext-translator

Usage

Use the Json generator of the gettext/gettext library to export the translations to json:

use Gettext\Translations;

//Load the po file with the translations
$translations = Translations::fromPoFile('locales/gl.po');

//Export to a json file
$translations->toJsonFile('locales/gl.json');

Load the json file in your browser (for example, using webpack) and use it

var Translator = require('gettext-translator');
var translations = require('locales/gl.json');

var i18n = new Translator(translations);

console.log(i18n.gettext('hello world')); //ola mundo

Sprintf

This library includes sprintf dependency implemented in the short methods like __, n__, etc...:

i18n.__('Hello %s', 'world'); //Hello world
i18n.n__('One comment', '%s comments', 12, 12); //12 comments

API

Long methodShort + sprintfdescription
gettext__Returns a translation
ngettextn__Returns a translation with singular/plural variations
dngettextdn__Returns a translation with domain and singular/plural variations
npgettextnp__Returns a translation with context and singular/plural variations
pgettextp__Returns a translation with a specific context
dgettextd__Returns a translation with a specific domain
dpgettextdp__Returns a translation with a specific domain and context
dnpgettextdnp__Returns a translation with a specific domain, context and singular/plural variations

Keywords

FAQs

Package last updated on 12 Oct 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc