Gathering detailed insights and metrics for @zakkudo/translate-webpack-plugin
Gathering detailed insights and metrics for @zakkudo/translate-webpack-plugin
Gathering detailed insights and metrics for @zakkudo/translate-webpack-plugin
Gathering detailed insights and metrics for @zakkudo/translate-webpack-plugin
A webpack plugin for generating localization files using static analysis of source files similar to gettext
npm install @zakkudo/translate-webpack-plugin
Typescript
Module System
Min. Node Version
JavaScript (84.35%)
Shell (15.65%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-3-Clause License
2 Stars
65 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Aug 10, 2021
Latest Version
0.3.0
Package Id
@zakkudo/translate-webpack-plugin@0.3.0
Unpacked Size
18.72 kB
Size
6.96 kB
File Count
4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A webpack plugin for scanning javscript files to build translation mappings in json automatically.
__()
or __n()
or __p()
or __np()
, will be picked up as a
translatable making usage extremely easy for developers1# Install using npm 2npm install @zakkudo/translate-webpack-plugin
1# Install using yarn 2yarn add @zakkudo/translate-webpack-plugin
__('text')
or __n('singlular', 'plural', number)
using a library like @zakkudo/translator
1const TranslateWebpackPlugin = require('@zakkudo/translate-webpack-plugin'); 2 3module.exports = { 4 plugins: [ 5 new TranslateWebpackPlugin({ 6 // Analyzes all javscript files in the src directory, which is a good initial value 7 files: 'src/**/*.js', 8 // Use verbose output to see what files are parsed, what keys are extracted, and where they are being written to 9 debug: true, 10 // You do not need to add your default language (which for most people will be English) 11 locales: ['fr'], 12 // Consolidate all of the optimized localizations into `src/.locale`, good as an initial configuration 13 target: 'src' 14 }) 15 ] 16};
.locales
to your .gitignore
so it isn't commited. It is a dynamic source file that has no value being added to a repository. Its existance in the src
directory is simply to facilitate importing it.find src -name '.locales' | xargs rm -r
to your clean scripts for an easy way to remove the auto generated src/.locales
from your source codesrc/.locales
folder so you can merge it into the lookup of @zakkudo/translator
. It is plain old json with the untranslated and unexisting values optimized out.locales
(without a period.) It's annoted with information about new, unused, and existing usages of the translations to help them audit what needs updating.You'll end up with a file structure similar to below.
File Structure
├── locales <- For your translators
│ ├── en.json
│ └── fr.json
└── src
├── .locales <- For your developers
│ ├── en.json
│ └── fr.json
└── pages
├── About
│ └── index.js
└── Search
└── index.js
Where locales/fr.json
will look like this for use by your translators:
1{ 2 "About": { 3 // NEW 4 // src/pages/AboutPage/index.js:14 5 "default": "" 6 }, 7 "Search": { 8 // UNUSED 9 "default": "French translation", 10 // UNUSED 11 "menuitem": "French translation" 12 }, 13 "There is one user": { 14 // src/pages/AboutPage/index.js:40 15 "default": {"1":"French translation", "2":"French translation"}, 16 }, 17 "Welcome to the about page!": { 18 // src/pages/AboutPage/index.js:38 19 "default": "French translation" 20 } 21}
And the optimized src/.locales/fr.json
will look like this for use by your developers:
1{ 2 "There is one user": {"one":"French translation", "other":"French translation"}, 3 "Welcome to the about page!": "French translation" 4}
Your developers will use the translation similarly to below:
1import Translator from '@zakkudo/translator'; 2import fr from 'src/.locales/fr.json'; 3const translator = new Translator(); 4const {__, __n} = translator; 5const language = navigator.language.split('-')[0]; 6 7translator.setLocalization('fr', fr); 8translator.setLocale(language); 9 10document.title = __('About'); 11document.body.innerHTML = __n('There is one user', 'There are %d users', 2);
.locales
directory1module.exports = { 2 plugins: [ 3 new TranslateWebpackPlugin({ 4 files: 'src/**/*.js', 5 locales: ['es', 'fr'], 6 target: 'src' 7 }); 8 ] 9};
File Structure
├── locales <- For your translators. Contains translations for everything
│ ├── es.json
│ └── fr.json
└── src
├── Application.js
├── .locales <- For your developers. Contains translations for everything
│ ├── es.json
│ └── fr.json
└── pages
├── About
│ └── index.js
└── Search
└── index.js
.locales
directory1module.exports = { 2 plugins: [ 3 new TranslateWebpackPlugin({ 4 files: 'src/**/*.js', 5 locales: ['es', 'fr'], 6 target: 'src/pages/*' 7 }) 8 ] 9};
File Structure
├── locales <- For your translators. Contains translations for everything
│ ├── es.json
│ └── fr.json
└── src
├── Application.js
└── pages
├── About
│ ├── .locales <- For your developers. Contains translations for `Application.js` and `About/index.js`
│ │ ├── es.json
│ │ └── fr.json
│ └── index.js
└── Search
├── .locales <- For your developers. Contains translations for `Application.js` and `Search/index.js`
│ ├── es.json
│ └── fr.json
└── index.js
@zakkudo/translation-static-analyzer
for the generic library that this
package thinly wraps@zakkudo/translator
is a library that can read the localization with
no fuss and apply the translations.Plugin for analyzing javascript source files, extracting the translations, and converting them into localization templates.
Kind: Exported class
Param | Type | Default | Description |
---|---|---|---|
options | Object | The modifiers for how the analyzer is run | |
options.files | String | A glob pattern of the files to pull translations from | |
[options.debug] | Boolean | false | Show debugging information in the console |
[options.locales] | Array.<String> | [] | The locales to generate (eg fr, ja_JP, en) |
[options.templates] | String | The location to store the translator translatable templates for each language. Defaults to making a locales directory in the current working directory | |
[options.target] | String | Where to write the final translations, which can be split between multiple directories for modularity. If there are no targets, no .locales directory will be generated anywhere. |
Method called by the webpack plugin system during watch to inform the plugin when some files have been updated.
Kind: instance method of TranslateWebpackPlugin
Param | Type | Description |
---|---|---|
compiler | Object | The webpack compiler object |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
71 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More