localization-skywork v1.0.0
Language Switcher
A lightweight JavaScript utility to handle multi-language support in web applications. This library allows you to retrieve translations for various languages based on a 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: Begin by defining 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
getTranslations
function 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 { getTranslations } 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...
};
// Fetch translations for a specific language (e.g., 'en' for English)
const selectedLang = getTranslations('en', translations);
console.log(selectedLang.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
9 months ago