Socket
Socket
Sign inDemoInstall

translation-web-component

Package Overview
Dependencies
8
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    translation-web-component

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


Version published
Weekly downloads
24
increased by1100%
Maintainers
2
Created
Weekly downloads
 

Changelog

Source

v1.1.2

  • Moved polymer-cli to devDependencies in package.json.

Readme

Source

<t-lang>

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>

Install

Save to your project.

npm install --save translation-web-component

Import into your app.

import 'translation-web-component/t-lang.js'

Demo or Develop

git clone https://github.com/ictatrti/translation-web-component
cd translation-web-component
npm install
npm start

Test

git clone https://github.com/ictatrti/translation-web-component
cd translation-web-component
npm install
npm run test 

FAQs

Last updated on 01 Jun 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc