Skip to content

Google Apps Script Snippet. I18nService is an object that implements internationalization functionality.

License

Notifications You must be signed in to change notification settings

MaksymStoianov/I18nService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BG | DE | EN | RU | UK

I18nService

I18nService is an object that implements internationalization functionality.

Installation

  1. Open your project in Google Apps Script Dashboard.
  2. Copy the contents of the index.js file and paste it into a new file in your Google Apps Script project.

Usage

Example 1

const data = {
  "bg": {
    title: "Тестово приложение"
  },
  "de": {
    title: "Testanwendung"
  },
  "en": {
    title: "Example Application"
  },
  "ru": {
    title: "Тестовое приложение"
  },
  "uk": {
    title: "Тестовий застосунок"
  }
};

const i18n = I18nService
  .init('ru')
  .load(data);

console.log(i18n.getLanguage('en').getTranslate('title'));
console.log(__('title'));

Example 2

const data = {
  title: "Example Application"
};
const locale = "en";

const i18n = I18nService
  .init(locale)
  .load(data, locale);

console.log(i18n.getLanguage(locale).getTranslate('title'));
console.log(__('title'));

Example 3

const sheet = SpreadsheetApp
  .getActiveSpreadsheet()
  .getSheetByName('I18n');

const i18n = I18nService
  .init('en')
  .load(sheet);

console.log(i18n.getLanguage('en').getTranslate('title'));
console.log(__('title'));

Tasks

  • Add the ability to load translations in json format via url-link to the I18n.load() method.
  • Use CacheService for language storage.

Changelog

  • 1.0.0: Release.

About

Google Apps Script Snippet. I18nService is an object that implements internationalization functionality.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published