Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Translate your vanilla websites or web apps using HTML attributes and a pinch of Javascript
npm i attr-i18n
# or
yarn add attr-i18n
First import and initialize the module.
import { AttrI18n } from 'attr-i18n';
const languages = ['English', 'हिन्दी', 'français'];
new AttrI18n(languages, {
attr: 'data-translation',
path: 'assets/translations',
debug: true,
togglerID: 'language-toggle',
defaultLang: languages[0]
});
Then in your HTML file(s):
togglerID
option above. This select element will toggle between languagespath
option above. Each of the language files should be named after the language name as it appears in the languages
array above.data-translation
attribute as set in the option attr
above by adding it to each element you want translated. The data-translation
attribute accepts a dot-delimited string which points to the translation you want to use.Name | Type | Required | Default | Description |
---|---|---|---|---|
attr | string | false | data-attr-i18n | HTML attribute which contains the translation key |
path | string | false | assets/attr-i18n | Path to the folder which contains the translation JSON file(s) |
debug | boolean | false | false | Turns debug mode on/off |
togglerID | string | false | attr-i18n-toggler | ID attribute for the language toggle HTML select element |
defaultLang | string | false | languages[0] | The default language. If not provided, the first one from the array is used |
<select id="language-toggle">
<option>English</option>
<option>हिन्दी</option>
<option>français</option>
</select>
<h1 data-translation="form.desc">Fill Your Details!</h1>
<div class="form-row">
<label data-translation="form.name">Name:</label>
<input type="text" name="UserName" size="35" maxlength="35" value="" data-translation="form.name" />
</div>
<div class="form-row">
<label data-translation="form.age">Age:</label>
<input type="number" name="Age" size="35" maxlength="35" value="" data-translation="form.age" />
</div>
<div class="form-row">
<p data-translation="form.exe.desc">Do you exercise at home?</p>
<ul>
<li>
<input type="radio" name="exe" value="1" />
<label data-translation="form.exe.yes">Yes</label>
</li>
<li>
<input type="radio" name="exe" value="2" />
<label data-translation="form.exe.no">No</label>
</li>
</ul>
</div>
MIT
FAQs
Internationalization for Vanilla JS projects
The npm package attr-i18n receives a total of 91 weekly downloads. As such, attr-i18n popularity was classified as not popular.
We found that attr-i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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 found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.