
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
localization-bar
Advanced tools
Detect a user's browser language and show a message for the user to view pages in their preferred language.
Detect a user's browser language and show a message for the user to view pages in their preferred language.
npm install localization-bar
import 'localization-bar'
// or
import LocalizationBar from 'localization-bar'
Import the class into your javascript. You'll then need to pass an object containing the options for the languages you want to use. Each language needs the following options.
message
- the copy shown in the barcta
- an object that containstext
- text displayed for the ctaurl
- url to the translated pagesHere is an example of what the object would look like.
const languageMap = {
es: {
message: 'Ver el sitio en',
cta: {
text: 'español',
url: '/es'
}
},
fr: {
message: 'Voir le site en',
cta: {
text: 'français',
url: '/fr'
}
}
};
By default the localization-bar will be appended to the top of the body element. If you would rather insert the bar into another part of the page, simply pass the selector of the element you want to insert before.
You can also override the browser's preferred language setting and pass a preferred language as an parameter when instantiating the class.
When you are ready to add the bar to the page call the check()
method.
Example:
const localizationBar = new LocalizationBar({
es: {
message: 'Ver el sitio en',
cta: {
text: 'español',
url: '/es'
}
},
fr: {
message: 'Voir le site en',
cta: {
text: 'français',
url: '/fr'
}
}
}, {
insertSelector: '.wrapper',
language: 'es'
});
localizationBar.check();
FAQs
Detect a user's browser language and show a message for the user to view pages in their preferred language.
The npm package localization-bar receives a total of 0 weekly downloads. As such, localization-bar popularity was classified as not popular.
We found that localization-bar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.