I18nService is an object that implements internationalization functionality.
- Open your project in Google Apps Script Dashboard.
- Copy the contents of the
index.js
file and paste it into a new file in your Google Apps Script project.
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'));
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'));
const sheet = SpreadsheetApp
.getActiveSpreadsheet()
.getSheetByName('I18n');
const i18n = I18nService
.init('en')
.load(sheet);
console.log(i18n.getLanguage('en').getTranslate('title'));
console.log(__('title'));
- Add the ability to load translations in
json
format viaurl-link
to theI18n.load()
method. - Use
CacheService
for language storage.
- 1.0.0: Release.