konsomejona / simplehtmllocalizer Goto Github PK
View Code? Open in Web Editor NEWSimply localize text inside your HTML webpage.
License: MIT License
Simply localize text inside your HTML webpage.
License: MIT License
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.
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.