Code Monkey home page Code Monkey logo

extract-gettext's Introduction

extract-getext

Build Status

Extract gettext strings from __('literal') and __n('single', 'plural', n ) functions in any source. This module currently only looks for the __ and __n. However, adding other signatures is trivial (see lex.js).

It does not do proper plurals - it just smashes everything into one flat structure, wich, actually, is similar to what the real xgettext does. When outputting a .json file, the format is usable by i18next-conv.

Install

npm install extract-gettext

Usage

CLI

extract-gettext -o strings.json /path/to/sources

API

( as taken from the "test" )

    test('scanner', function(assert) {
        var expect = ['Plain old singluar',
          'as the other',
          'duplicate strings are filtered',
          'error, but it works',
          'even mixing goes',
          'like this',
          'one on the same line',
          'or that',
          'plural',
          'single'];
    
        scan(__dirname + '/../test/*', function(err, strings) {
            assert.deepEqual(strings, expect, 'Retrieved expected strings');
            assert.end();
        });
    });

background

I wasn't going to write yet another variety of xgettext. xgettext has good support for javascript, and extracts strings faster then this tool. However, I need a little bit of flexibility. xgettext is hardcoded for the _('literal') notation, a namespace usually occupied by lodash in my world. As a small benefit, this small variety uses a simple lexer to extract translations, but it really doesn't care what programming language you've written your files in.

That may come in handy one day for coffeescript, typescript or even ES6.

Some other good tools exist, such as:

roadmap and future development

I'm propably not going to update this tool as it works for me and it works fast and decent enough. I have too little knowledge of the various .json and .po formats for pluralization and the "specs" seem a bit ambigious to me. However, maybe I misread something, so if you would like to use this and need this type of functionality, send me an example of the desired output format with some explaination :)

extract-gettext's People

Contributors

mvhenten avatar gannetson avatar aethemba avatar eodolphi avatar rollick avatar

Watchers

 avatar  avatar James Cloos avatar  avatar  avatar Jhon avatar Ashutosh avatar Pieter Rees avatar Hodor the Great ✝ avatar  avatar Maurice Kleine avatar Daniël Kroon avatar  avatar Anne van Gorkom avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.