GithubHelp home page GithubHelp logo

konsomejona / simplehtmllocalizer Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 3.0 37 KB

Simply localize text inside your HTML webpage.

License: MIT License

HTML 42.17% JavaScript 57.83%
html i18n javascript language localization translation

simplehtmllocalizer's People

Contributors

konsomejona avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simplehtmllocalizer's Issues

document.registerElement is deprecated and will be removed in M80

As i see registerElement will be removed on february 2020, what is the alternative of registerElement?

[Deprecation] document.registerElement is deprecated and will be removed in M80, around February 2020. Please use window.customElements.define instead. See https://www.chromestatus.com/features/4642138092470272 and https://developers.google.com/web/updates/2019/07/web-components-time-to-upgrade for more details.

I tried use window.customElements.define but get this error:

Uncaught TypeError: Failed to execute 'define' on 'CustomElementRegistry': The callback provided as parameter 2 is not a function.

Use with select `option` elements

Currently you can't use this to localize <option> elements in <select>. Adding a localized-option element would allow this:

customElements.define('localized-option', LocalizedOptionElement, { extends: 'option' });

class LocalizedOptionElement extends HTMLOptionElement {
    constructor() {
        super();
    }

    connectedCallback() {
        var key = this.hasAttribute('key') ? this.getAttribute('key') : '';
        var lang = this.hasAttribute('lang') ? this.getAttribute('lang') : getLang();
        this.innerHTML = translate(key, lang);
    }
}

It's used like this.

<select class="form-select" name="sel" id="my-select">
  <option is="localized-option" key="Off" value="0"></option>
  <option is="localized-option" key="On" value="1"></option>

I'd also suggest changing translate so that missing dictionary keys translate to the key name automatically.

function translate(key, lang) {
    var dict = (lang in dictionary) ? dictionary[lang] : dictionary['_']
    return key in dict ? dict[key] : key;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.