Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@skroutz/i18n-webpack-plugin
Advanced tools
i18n (localization) plugin for Webpack.
Forked from webpack-contrib/i18n-webpack-plugin.
npm i -D @skroutz/i18n-webpack-plugin
Or
yarn add @skroutz/i18n-webpack-plugin -D
This plugin creates bundles with translations baked in. So you can serve the translated bundle to your clients.
plugins: [
...
new I18nPlugin(localization, options)
],
localization
: object, a key-value map of localization stringsoptions.isDefaultLocale
: boolean, is this language the default oneFor functions that use %{dynamicPart}
, you can extend the String
prototype with a supplant method, like so:
String.prototype.supplant = function(o) {
return this.replace(
/%\{([^{}]*)\}/g,
(a, b) => {
const r = o[b];
return (typeof r === 'string' || typeof r === 'number') ? r : a;
}
);
};
Then, you can use the following functions in your code:
__(msgid)
Basic translation methodMarks a string as translatable:
__('Hello World!');
To translate a string with dynamic parts:
__('Hello %{username}. Welcome to %{sitename}.').supplant({
username: User.username,
sitename: App.sitename
});
n__(*msgid, n)
Pluralized translationsTo return the singular or plural form depending on how many you have:
n__('shop', 'shops', shop_count);
Additionally, to include the counter in the translated text:
n__('%{stars_count} star', '%{stars_count} stars', Shop.rating.stars).supplant({
stars_count: Shop.rating.stars
});
s__(msgid)
Scoped translationsTo provide context to the translation:
s__('Gender|Female');
s__('Formal|Are you sure?');
s__('VolumetricUnit|kg');
FAQs
Embed localization into your bundle
We found that @skroutz/i18n-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.