localization-skywork
v1.0.1
Published
A lightweight JavaScript utility to handle multi-language support in web applications. This library provides a `Localization` class to retrieve translations based on a specified language code and a predefined list of translations.
Downloads
143
Readme
Language Switcher
A lightweight JavaScript utility to handle multi-language support in web applications. This library provides a Localization
class to retrieve translations based on a specified language code and a predefined list of translations.
Table of Contents
Installation
Simply download the code or integrate it directly into your project as an independent module.
Usage
Define Translations: Start by creating an object that holds all the translation texts for each language. Each language is represented as an object with specific key-value pairs for the translations.
Retrieve Translations: Use the
Localization
class to retrieve the translations for a specific language code. If the requested language code is unavailable, the function will default to English (en
).
Importing and Using the Library
import { Localization } from './path/to/your/module';
// Define translations for your application
const translations = {
en: {
greeting: "Hello, welcome to our site!",
description: "This is a description in English.",
},
id: {
greeting: "Halo, selamat datang di situs kami!",
description: "Ini adalah deskripsi dalam Bahasa Indonesia.",
},
// Additional languages as needed...
};
// Initialize the Localization instance with a specific language
const localization = new Localization('en', translations);
// Fetch translations for the selected language
const selectedTranslations = localization.getTranslations();
console.log(selectedTranslations.greeting); // Outputs: Hello, welcome to our site!
How to Publish on NPM
The following steps will help you publish a package to NPM.
npm login
npm publish
npm publish --access public