Get started with l20n CDN
Apache-2.0 licensed
L20n is a JS internationalization library that simplifies the process of managing translations for web applications.
Tags:- localization
- l10n
Stable version
Copied!
How to start using l20n CDN
<!DOCTYPE html>
<html>
<head>
<title>Get started with l20n CDN - cdnhub.io</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/i18next.min.js"></script>
<script src="https://cdn.cdnhub.io/l20n/1.0.2/l20n.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/i18next-browser-languagedetector.min.js"></script>
<script src="locale/en.json"></script>
<script src="locale/es.json"></script>
</head>
<body>
<button id="change-language">Change Language</button>
<script>
const i18n = new I18n({
lng: 'en',
fallbackLng: 'en',
resources: {
en: require('./locale/en.json'),
es: require('./locale/es.json'),
},
});
document.getElementById('change-language').addEventListener('click', () => {
i18n.changeLanguage('es');
});
i18n.init();
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('[data-i18n]').forEach((el) => {
el.textContent = i18n.t(el.dataset.i18n);
});
});
</script>
</body>
</html>
Copied!
Copied!