Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@transferwise/translation-helper
Advanced tools
A translation helper mainly used in Webpack context.
This is a translation helper for Webpack. It is used to create specific bundles for each of your supported languages in addition to the bundle containing all the languages, automatically. This allows us to serve only the messages we need for a certain locale to the customers, decreasing the payload size.
The setup is complicated, but after that, even with new language additions, no modifications are needed.
npm install --save-dev @transferwise/translation-helper
import path from 'path';
import TranslationHelper from '@transferwise/translation-helper'; // 1
const messagesPath = path.join(__dirname, 'translations'); // 2
const translationHelper = new TranslationHelper({
messagesPath, // required
messagesFileNameBase: 'my-messages', // default: 'messages'
messagesExtension: 'myjson', // default: 'json'
}); // 3
translationHelper.init(); // 4
module.exports = translationHelper.getLanguageCodesWithAll().map(code => ({ // 5
entry: ...,
output: {
path: path.join(__dirname, 'dist', translationHelper.getPathForCode(code)), // 6
filename: `output${translationHelper.getSuffixForCode(code)}.js`, // 7
},
module: ...,
resolve: {
alias: {
translations: path.join(messagesPath, translationHelper.getMessagesFileNameForCode(code)), // 8
},
},
}));
TranslationHelper
classTranslationHelper
with:Option | Description | Default |
---|---|---|
messagesPath | Absolute path for the directory containing all your messages files | * required |
messagesFileNameBase | File name base for messages files (your source messages file name without the extension) | messages |
messagesExtension | Extension for messages files | json |
i18n
directory.output.js
instead of output.all.js
.import translations from 'translations';
in your translations config.angular
with angular-translate
:import translations from 'translations';
...
$translateProvider.translations(languageCode, translations[languageCode] || translations);
...
With the following files:
.
├── node_modules
├── translations
│ ├── messages.json
│ ├── messages.en.json
│ ├── messages.en-US.json
│ └── messages.it.json
├── package.json
└── webpack.config.js
messagesPath
would be path.join(__dirname, 'translations')
messagesFileNameBase
would be 'messages'
(default)
messagesExtension
would be 'json'
(default)
translationHelper.init()
would create a messages.all.json
file in translations
with the following structure:
{
"en": {
...
},
"en-US": {
...
},
"it": {
...
}
}
translationHelper.getLanguageCodesWithAll()
would return ['all', 'en', 'en-US', 'it']
, so in total, we would create four bundlestranslations
would be the all
format shown above with translations objects as values of the language codes in case of the all-inclusive bundle, or just the translations object in case of language bundlesoutput.path
is specified as path.join(__dirname, 'dist', translationHelper.getPathForCode(code))
and the output.filename
is `output${tran`slationHelper.getSuffixForCode(code)}.js`
, we would get the following end result:.
├── dist
│ ├── output.js
│ ├── i18n
│ │ ├── output.en.js
│ │ ├── output.en-US.js
│ │ └── output.it.js
├── node_modules
├── translations
│ ├── messages.json
│ ├── messages.all.json # not to be committed
│ ├── messages.en.json
│ ├── messages.en-US.json
│ ├── messages.it.json
├── package.json
└── webpack.config.js
Ideally, this should be a Webpack plugin, allowing us to decrease the number of contact points.
For features and bugs, feel free to add issues or contribute.
npm run test:watch
. For a single-run check with ESLint, run npm test
.package.json
according to semver and add an item that a release will be based on to CHANGELOG.md
.package.json
.FAQs
A translation helper mainly used in Webpack context.
We found that @transferwise/translation-helper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 65 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.