Code Monkey home page Code Monkey logo

js-translation-extractor's Introduction

Coffreo/js-translation-extractor

By Coffreo

Build Status codecov

Javascript translations extractor for willdurand/js-translation-bundle

This package is a small project existing to store in one place wonderfuls regexps to properly export translations strings & metas from javascript source files.
It can be used standalone, but it's main goal is to be used in :

Installation

Features

  • extracts following strings from javascript files like a pro
trans('MESSAGE', {param: 'foo'}, 'DOMAIN')
//    ^ 1st parameter is translation message
//                               ^ 3rd parameter is translation domain

transChoice('MESSAGE_WITH_PLURALS', 3, {param: 'foo'}, 'DOMAIN')
//          ^ 1st parameter is translation message      
//                                                     ^ 4th parameter is translation domain

// others parameters aren't extracted because they are useless. 

Note that this is the syntax used by js-translation-bundle

  • allow string delimiters to be " or '
  • extracts multi-lines commands

Usage

use Coffreo\JsTranslationExtractor\Extractor\JsTranslationExtractor;
use Coffreo\JsTranslationExtractor\Model\TranslationCollection;

$extractor = new JsTranslationExtractor();
$translationCollection = new TranslationCollection();

$extractor->extract(<<<FILECONTENT
import Translator from 'bazinga-translator';

export default () => Translator.trans('This is awesome', {}, 'foo');
export {
    bad: () => Translator.trans('This is ugly');
};
FILECONTENT
    , $translationCollection);

$first = $translationCollection->first();
$first->getMessage();  // This is awesome
$first->getLine();     // 3
$first->getContext();  // ['domain' => 'foo']

$second = $translationCollection->get(1);
$second->getMessage();  // This is ugly
$second->getLine();     // 5
$second->getContext();  // []

Found a bug

Please fill an issue with informations to reproduce bug.

If your translated strings are not extracted properly, please provide a sample failing string.

Development

  • Clone repository
  • Execute
make [install]   # to init composer after install
make test        # to run test

TODO

  • Find a way to add and extract desc/meaning values

License

This project is licensed under the MIT License - see the LICENSE file for details

js-translation-extractor's People

Contributors

emri99 avatar paali avatar

Stargazers

Filinto Romain avatar

Watchers

James Cloos avatar  avatar  avatar

js-translation-extractor's Issues

Don't support translation inside translation parameter

Sample:

Translator.trans('issue', {
  name: Translator.trans('param', {}, 'paramDomain'),
}, 'issueDomain')),
  • will extract { key: "issue", domain: "paramDomain" } instead of { key: "issue", domain: "issueDomain" }
  • won't extract { key: "param", domain: "paramDomain" }

Removing line breaks don't change anything

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.