Skip to content

Effortlessly manage internationalization in TypeScript with ts-iTranslate.

Notifications You must be signed in to change notification settings

alisamirali/ts-iTranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-iTranslate

ts-iTranslate is a lightweight TypeScript library for seamless internationalization (i18n) in web applications. It offers simple language switching and translation support, making it easy to create multilingual user interfaces.

Installation

Install the package using npm:

npm install ts-iTranslate

Usage

  • Importing
import I18n from "ts-iTranslate";

Setting up Translation Maps

  • Define your translation maps for each language:
const translations = {
  en: {
    greeting: "Hello!",
  },
  ar: {
    greeting: "مرحبًا!",
  },
};

Creating an Instance

  • Create an instance of the I18n class with the default language and translations:
const i18n = new I18n("en", translations);

Setting the Current Language

  • Set the current language, for example, based on the user's preferred language:
i18n.setLanguage("ar");

Translating Strings

  • Use the translate function to get localized strings:
const greeting = i18n.translate("greeting");

console.log(greeting); // Outputs "مرحبًا!"

License

About

Effortlessly manage internationalization in TypeScript with ts-iTranslate.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published