Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
translation-web-component
Advanced tools
A large single translation file for an app creates a disconnect between content and context. Provide translations inline with your HTML using `<t-lang>` element. Set `<html lang="[language-code]">` on your document and in your content provide `<t-lang [la
Changelog
v1.1.2
Readme
A large single translation file for an app creates a disconnect between content and context. Provide translations inline with your HTML using <t-lang>
element. Set <html lang="[language-code]">
on your document and in your content provide <t-lang [language-code]>Translation content...</t-lang>
. If your app changes language after the page loads, fire the lang-change
event with document.body.dispatchEvent(new CustomEvent('lang-change'))
to notify the t-lang
elements.
Example of showing a page title in English...
<!doctype html>
<html lang="en">
...
<body>
<h1>
<t-lang en>Hello</t-lang>
<t-lang fr>Bonjour</t-lang>
</h1>
<button onclick="
document.documentElement.lang = 'en';
document.body.dispatchEvent(new CustomEvent('lang-change'));
">
Enable English
</button>
<button onclick="
document.documentElement.lang = 'fr';
document.body.dispatchEvent(new CustomEvent('lang-change'));
">
Enable French
</button>
</body>
</html>
Now in French...
<!doctype html>
<html lang="fr">
...
<body>
<h1>
<t-lang en>Hello</t-lang>
<t-lang fr>Bonjour</t-lang>
</h1>
<button onclick="
document.documentElement.lang = 'en';
document.body.dispatchEvent(new CustomEvent('lang-change'));
">
Enable English
</button>
<button onclick="
document.documentElement.lang = 'fr';
document.body.dispatchEvent(new CustomEvent('lang-change'));
">
Enable French
</button>
</body>
</html>
Now with buttons to switch between the two translations...
<!doctype html>
<html lang="en">
...
<body>
<h2>
<t-lang en>Hello</t-lang>
<t-lang fr>Bonjour</t-lang>
</h2>
<button onclick="
document.documentElement.lang = 'en';
document.body.dispatchEvent(new CustomEvent('lang-change'));
">
Enable English
</button>
<button onclick="
document.documentElement.lang = 'fr';
document.body.dispatchEvent(new CustomEvent('lang-change'));
">
Enable French
</button>
</body>
</html>
Save to your project.
npm install --save translation-web-component
Import into your app.
import 'translation-web-component/t-lang.js'
git clone https://github.com/ictatrti/translation-web-component
cd translation-web-component
npm install
npm start
git clone https://github.com/ictatrti/translation-web-component
cd translation-web-component
npm install
npm run test
FAQs
A large single translation file for an app creates a disconnect between content and context. Provide translations inline with your HTML using `<t-lang>` element. Set `<html lang="[language-code]">` on your document and in your content provide `<t-lang [la
The npm package translation-web-component receives a total of 24 weekly downloads. As such, translation-web-component popularity was classified as not popular.
We found that translation-web-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.