Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@gucciogucci/simply-translation
Advanced tools
A very simple translation component focused only on translation words divided by JSON files with default language.
The component uses browser language as first choice and default in case of the translation file is missed.
The system uses Unicode language naming, like en-US
or en-GB
.
npm install @gucciogucci/simply-translation
Translation file is a JSON format, this is an example:
File en.json
{
"btnCancel": "cancel",
"btnClose": "close",
"welcome": "Hello {0} {1}"
}
Please note the 'welcome' key with the attributes annotations
You need to use a JSON file per language in your project, the structure should be like this:
src
└── asset
└── i18n
├── en.json
└── it.json
In the main file, usually App.js
, import the component and set it up like this:
// import component with set up and translation function
import loadTranslation, { simplyTranslate } from '@gucciogucci/simply-translation';
// import translation lib
import en from './asset/i18n/en.json';
import it from './asset/i18n/it.json';
// set up
loadTranslation({
default: 'en-US',
languages: {
'en-US': en,
'it-IT': it,
}
});
By default, SimplyTranslation use browser language as language selector, you can change it adding source
value to url_pathname_slot2 path or html lang attribute:
attribute name | required | type | value | description |
---|---|---|---|---|
default | yes | {string} | en | set up default JSON file |
source | no | {string} | null | url_pathname_slot2 | html | - null or blank: use browser language - url_pathname_slot2: use URL second slot (e.g.: https://www.domain.com/uk/it/ lang will be it) - html: use HTML lang attribute <html lang="en" ... > |
languages | yes | {object} | {'en-US': en, 'it-IT': it, ...} | mapping languages files |
Example:
loadTranslation({
default: 'en',
source: 'url_pathname_slot2',
languages: {
'en': en,
'zh_hk': zh_hk,
'zh': zh,
}
});
First import the component and then call it with the corresponding key and add attributes in an array in case.
Please check the translation JSON file as example
import { simplyTranslate } from '@gucciogucci/simply-translation';
simplyTranslate('btnCancel'); //= cancel
simplyTranslate('welcome', ['Laura', 'Brown']); //= Hello Laura Brown
Copyright 2021 Gucci.
Licensed under the GNU Lesser General Public License, Version 3.0
FAQs
Simply Translation library
The npm package @gucciogucci/simply-translation receives a total of 1 weekly downloads. As such, @gucciogucci/simply-translation popularity was classified as not popular.
We found that @gucciogucci/simply-translation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.