Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Js Translation Extractor Laravel Package

coffreo/js-translation-extractor

Extracts Laravel translation strings used in JavaScript by scanning your frontend source. Helps keep locale files in sync with JS usage and reduces missing-key issues in mixed Blade/Vue/React apps.

View on GitHub
Deep Wiki
Context7

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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky