Gettext Style i18n for Modern JavaScript Apps

Related tags

I18n And L10n Jed
Overview

Build Status

Jed

Gettext Style i18n for Modern JavaScript Apps

For more info, please visit the docs site at http://messageformat.github.io/Jed.

You sure you don't want something more modern?

Jed is feature complete in my opinion. I am happy to fix bugs, but generally am not interested in adding more to the library.

I also maintain messageformat.js. If you don't specifically need a gettext implementation, I might suggest using MessageFormat instead, as it has better support for plurals/gender and has built-in locale data.

Parsing Gettext Files

Jed doesn't include a Gettext file parser, but several third-party parsers exist that can have their output adapted for Jed.

Node

Just search the npm repository, there are several PO and MO file parsers available.

Browser

Jed Gettext Parser is the only known browser MO file parser, and it also works in Node, and outputs Jed-compatible data directly.

gettext.js and Pomo.js both include browser-compatible PO file parsers.

Todo

  • Build time generation of plural form functions
  • Web interface for building translation sets
  • Code introspection for default values

License

Jed is a member project of the JavaScript Foundation

You may use this software under the MIT License.

Contributor License Agreement

We require all contributions to be covered under the JS Foundation's Contributor License Agreement. This can be done electronically and essentially ensures that you are making it clear that your contributions are your contributions, you have the legal right to contribute and you are transferring the copyright of your works to the JS Foundation.

If you are an unfamiliar contributor to the committer assessing your pull request, it is best to make it clear how you are covered by a CLA in the notes of the pull request. The committer will verify your status.

If your GitHub user id you are submitting your pull request from differs from the e-mail address which you have signed your CLA under, you should specifically note what you have your CLA filed under (and for CCLA that you are listed under your company's authorised contributors).

Author

Credits

A good chunk of sanity checking was done against the gettext.js tests. That was written by:

  • Joshua I. Miller

The sprintf implementation is from:

  • Alexandru Marasteanu

The name

The name jed.js is an homage to Jed Schmidt (https://github.com/jed) the JavaScript community member who is a japanese translator by day, and a "hobbyist" JavaScript programmer by night. Give your kids three character names and they'll probably get software named after them too.

Comments
  • po2json for new Jed format

    po2json for new Jed format

    Hey Jed folks! A couple of us were having a discussion about the new Jed format downstream at mikeedwards/po2json#32 . We're trying to figure out what the best output for something like this:

    msgid "one product"
    msgid_plural "%d products"
    msgstr[0] "jeden produkt"
    msgstr[1] "%d produkty"
    msgstr[2] "%d produktów"
    

    We were outputting (correctly or not):

             "one product": [
                "%d products",
                "jeden produkt",
                "%d produkty",
                "%d produktów"
             ],
    

    Would it be like this now that the zeroth element is being lopped off?

             "one product": [
                "jeden produkt"
             ],
             "%d products": [
                "jeden produkt",
                "%d produkty",
                "%d produktów"
             ]
    
    opened by mikeedwards 11
  • Key name for storing plural forms from po2json doesn't match

    Key name for storing plural forms from po2json doesn't match

    po2json outputs the plural forms with a key of Plural-Forms (https://metacpan.org/source/GETTY/Locale-Simple-0.011/bin/po2json#L110) and it looks like Jed wants it under a key of plural_forms

    I'm guessing there is no such thing as a spec for PO-as-json so perhaps Jed just needs to look at both keys?

    Thoughts? If you are happy with this approach than I'll throw together a quick PR.

    opened by ashb 7
  • 0-index null

    0-index null

    Hi, this has been bugging me for a while

    // Note: by convention, the 0-index location of the translations // is never accessed. It's just a thing, I guess.

    what does this mean, convention by whom ? I look at my po files and all of them have all useful data.

    They don't have any useless translation that is never accessed, so where is this convention coming from. For kicks I've been going through the source code and deleting all ' + 1' there and there, and with an ugly

    val_list = _.compact(val_list);

    It just works, but there's no waste of an empty index in an array. Why would I parse an mo file to generate empty data ?

    opened by Sinewyk 6
  • string extraction from JS for po/pot files

    string extraction from JS for po/pot files

    Hi,

    I'm currently using xgettext in Python mode, but there are quite a few edge cases where it doesn't work correctly. How do you extract gettext keys from your JS files?

    thanks, Florian

    opened by theflow 6
  • Readme says that Jed ignores the first element of the translated array, but that's no longer the case.

    Readme says that Jed ignores the first element of the translated array, but that's no longer the case.

    In commit 8cc37367d55eda9f800f3a4fa5fab6b5756e9ad7, it looks like the expected format of locale_data changed so that the first element of the translated data array is no longer supposed to be a null. That's at odds with what's on the doc site http://slexaxton.github.io/Jed/ and a lot of the examples on the web. po2json, which I was using to parse my po files, doesn't output the right format anymore. Please update the doc and examples.

    opened by emosesSfdc 5
  • make test: Fix mocha timeout @ 'Plural Forms Parsing should have the sam...

    make test: Fix mocha timeout @ 'Plural Forms Parsing should have the sam...

    Hey,

    With this fix make test is error free! My Mac needs 6 seconds with the current HEAD, Travis CI needs 3 seconds. This patched version is a bit less than 1 second on my Mac, so it should be half a second on Travis CI which is way less than mocha's default timeout of 2 seconds...

    expect.js's be and to functions aren't really complex but heavy enough to be more than 6x slower than a simple !== + throw.

    Cheers, Philip

    opened by psilva261 5
  • Plurals and xgettext

    Plurals and xgettext

    Hi,

    I'm trying to get my messages.po from Javascript files using Jed. I'm using xgettext and this command:

      xgettext --keyword=translate --from-code utf-8 -L Perl `find . -iname "*.js"`
    

    It seems to work fine, but the problem comes when xgettext finds plurals like the next ones:

    i18n.translate("Pass through %1$s %2$s").fetch(var1, var2);

    Because it doesn't recognizes $ as a valid character. Is there any work around using xgettext, or otherwise, any other way to use a different numbering method xgettext-compatible?

    Thanks.

    opened by versae 5
  • Load sprintf.js via npm

    Load sprintf.js via npm

    This requires the sprintf.js npm module instead of inlining it and updates the library from 0.7-beta1 to version 1.0.3. A few changes to the tests were required to accommodate for the change.

    See #41.

    opened by swissspidy 4
  • Wrong URL

    Wrong URL

    At the top of https://github.com/messageformat/Jed and in https://www.npmjs.com/package/jed, the URL http://slexaxton.github.com/Jed is written instead of http://messageformat.github.io/Jed

    opened by DamienCassou 3
  • removed every 0-index from i18n, pass all tests

    removed every 0-index from i18n, pass all tests

    All green.

    If using semver, should be a major version because not backwards compatible ... my bad.

    Should go hand in hand with WrinklyNinja/jed-gettext-parser#6

    I would say don't merge this until its analog for parsing is ready.

    opened by Sinewyk 3
  • generate .po's

    generate .po's

    Thanks for Jed!

    I'm looking into generating the .po files from my source. I wondered how you do/did that?

    I started working on contributions to an existing package (handelbars-xgettext), but there must be something already out there?

    opened by smhg 3
  • Manifest repo url is blocked by firefox

    Manifest repo url is blocked by firefox

    The repository url in the package.json contains a username, which causes problems in some browsers. https://github.com/messageformat/Jed/blob/351c47d5c57c5c81e418414c53ca84075c518edb/package.json#L8

    By opening this link in firefox the browser attempts to login to github with the SlexAxton username and shows the following error:

    You are about to log in to the site “github.com” with the username “SlexAxton”, but the website does not require authentication. This may be an attempt to trick you.

    opened by wrenger 1
  • Add

    Add "trigger plural on boolean" and "trigger plural with variables on boolean" methods

    I wrote a small implementation of the gettext concept recently and wanted to provide two new methods to the community. I was writing these in React Native, as shown below, and would be happy to incorporate the pure JS equivalents into this project for Hacktoberfest! 🎃🎃🎃

    In short, the first method pboolgettext returns the plural form if a boolean is true or the singular form if the boolean is false. This is a case when no variables need to be inserted.

    The second, pvboolgettext, does the same, but formats the plural message with variables.

    /*
        * Returns the singular form of the message if a given boolean condition is true, otherwise the plural form.
        *
        * usage : pgettext(singularMessageId: string, pluralMessageId: string, b: boolean)
        *
        * @param singularMessageId <string> : the message ID to be used if the number of elements specified is zero
        * @param pluralMessageId <string> : the message ID to be sued if the number of elements specified is greater than zero
        * @param b <boolean> : a condition indicating if the singular message form should be displayed or not
         */
        pboolgettext(singularMessageId: string, pluralMessageId: string, b: boolean) {
            if (typeof singularMessageId === "undefined" || typeof singularMessageId === "undefined" || typeof b === "undefined") {
                throw "pboolgettext: Invalid arguments";
            }
            return b ? this.translations[singularMessageId] : this.translations[pluralMessageId];
        }
    
        /*
        * Returns the singular form of the message if a given boolean condition is true, otherwise the plural form formatted with variables.
        *
        * usage : pgettext(singularMessageId: string, pluralMessageId: string, b: boolean, value: any)
        * usage : pgettext(singularMessageId: string, pluralMessageId: string, b: boolean, values: [any, ... ,any])
        *
        * Note : variables can be mixed string and number.
        *
        * @param singularMessageId <string> : the message ID to be used if the number of elements specified is zero
        * @param pluralMessageId <string> : the message ID to be sued if the number of elements specified is greater than zero
        * @param b <boolean> : a condition indicating if the singular message form should be displayed or not
        * @param v <any> : the variable or variables to insert into the plural string
         */
        pvboolgettext(singularMessageId: string, pluralMessageId: string, b: boolean, ...values) {
            if (typeof singularMessageId === "undefined" || typeof singularMessageId === "undefined" || typeof b === "undefined" || typeof values === "undefined") {
                throw "pvboolgettext: Invalid arguments";
            }
            if (b) {
                return this.translations[singularMessageId];
            }
            return this.vngettext(pluralMessageId, ...values);
        }
    
    opened by dm20 0
  • Translations extraction

    Translations extraction

    Hi,

    How does one generate .pot from the source code using Jed? I assume that gettext won't be able to parse the calls to Jed since the syntax is too complex. If that's so, what are the alternatives?

    Cheers, Andrej

    opened by pronebird 1
  • Confusing plural examples

    Confusing plural examples

    There are two examples of plural forms on this page

    1. "%d key" : [ "%d key", "%d keys" ],
    2. "test singular": ["test plural", "test_1 singular", "test_1 plural"],

    These appear to be different structures. Using Gettext terminology they look like:

    1. msgid: [ msgstr1, msgstr2 ]
    2. msgid: [ msgid_plural, msgstr1, msgstr2 ]

    Can you please clarify how this structure should be used and whether it has changed at some point?

    opened by timwhitlock 1
  • Update sprintf

    Update sprintf

    Currently, Jed uses sprintf 0.7 which is more than four years old and contains several bugs which are meanwhile fixed (for example huh?).

    @SlexAxton do you think, this could be updated? maybe even made a dependency in package.json?

    opened by ghost 1
ICU MessageFormat for Javascript - i18n Plural and Gender Capable Messages

messageformat The experience and subtlety of your program's text can be important. Messageformat is a mechanism for handling both pluralization and ge

null 1.6k Dec 23, 2022
ICU MessageFormat for Javascript - i18n Plural and Gender Capable Messages

messageformat The experience and subtlety of your program's text can be important. Messageformat is a mechanism for handling both pluralization and ge

null 1.6k Dec 23, 2022
Internationalization for react done right. Using the i18next i18n ecosystem.

react-i18next IMPORTANT: Master Branch is the new v10 using hooks. $ v10.0.0 npm i react-i18next react-native: To use hooks within react-native, you m

i18next 7.9k Dec 30, 2022
Extract and merge i18n xliff translation files for angular projects.

Angular extract i18n and merge This extends Angular CLI to improve the i18n extraction and merge workflow. New/removed translations are added/removed

Daniel Schreiber 86 Jan 5, 2023
Merges XLIFF 1.2/2.0 files. Usable for Angular i18n automation.

XLIFF Simple Merge This program automates the merging of XLIFF files (version 1.2 and 2.0). New translations from the input file (e.g. "messages.xlf")

Daniel Schreiber 9 Dec 15, 2022
The alternative internationalization (i18n) library for Angular

NGX Locutus The alternative Angular Translation Library used for large scale microfrontend translations. No more worrying about shared translation ass

Stefan Haas 9 May 31, 2022
Type-safe internationalization (i18n) for Next.js

Type-safe internationalization (i18n) for Next.js Features Usage Examples Scoped translations Change current locale Use JSON files instead of TS for l

Tom Lienard 251 Dec 22, 2022
Give your JavaScript the ability to speak many languages.

Polyglot.js Polyglot.js is a tiny I18n helper library written in JavaScript, made to work both in the browser and in CommonJS environments (Node). It

Airbnb 3.6k Jan 2, 2023
:orange_book: simple approach for javascript localization

ttag ⚠️ This project was previously named c-3po. Some of the talks, presentations, and documentation may reference it with both names. Modern javascri

ttag 307 Jan 2, 2023
lightweight jQuery plugin for providing internationalization to javascript from ‘.properties’ files

jQuery.i18n.properties About jQuery.i18n.properties is a lightweight jQuery plugin for providing internationalization to javascript from ‘.properties’

null 408 Dec 25, 2022
A JavaScript Internationalization Framework

FBT is an internationalization framework for JavaScript designed to be not just powerful and flexible, but also simple and intuitive. It helps with th

Facebook 3.8k Jan 8, 2023
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript

Linguijs ?? ?? A readable, automated, and optimized (5 kb) internationalization for JavaScript Documentation · Documentation 2.x · Quickstart · Exampl

Lingui 3.5k Jan 2, 2023
i18n-language.js is Simple i18n language with Vanilla Javascript

i18n-language.js i18n-language.js is Simple i18n language with Vanilla Javascript Write by Hyun SHIN Demo Page: http://i18n-language.s3-website.ap-nor

Shin Hyun 21 Jul 12, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Simplest ever I18N 1 KB library for HTML/JavaScript apps.

Ultimate I18n JS ?? Ultimate internationalization library for web applications. Super simple & easy. Less than 1KB (minified and gziped). 0 dependenci

Bart Tadych 8 Dec 22, 2022
human friendly i18n for javascript (node.js + browser)

BabelFish - human friendly i18n for JS Internationalisation with easy syntax for node.js and browser. Classic solutions use multiple phrases for plura

Nodeca 246 Nov 20, 2022
ICU MessageFormat for Javascript - i18n Plural and Gender Capable Messages

messageformat The experience and subtlety of your program's text can be important. Messageformat is a mechanism for handling both pluralization and ge

null 1.6k Dec 23, 2022
ICU MessageFormat for Javascript - i18n Plural and Gender Capable Messages

messageformat The experience and subtlety of your program's text can be important. Messageformat is a mechanism for handling both pluralization and ge

null 1.6k Dec 23, 2022