i18n for Google Workspace Add-on

Hi Google Workspace Developer Community!

We're a building an hybrid office platform for Google Workspace called Comeen

 

Our application is available on the Google Workspace Marketplace

Since we're starting to deploy Enterprise grade customers with offices around the world, we need to translate our Google Workspace Add-on in severals languages : french, english, and more.

Is there best practices to do so or should we use "if" conditions to adapt the add-on's languages to the connected user?

Best,

Benjamin.

Solved Solved
1 2 431
1 ACCEPTED SOLUTION

Stephane_fr
Google Developer Expert
Google Developer Expert

Hi Benjamin

 

In Google Wroksapce Add-on you have a specific object to get user local : https://developers.google.com/workspace/add-ons/how-tos/access-user-locale

 

After for the application on my side for an internal I just implemened a javascript code to translate text when needed.

 

var LANG = {
en : {select_template:"Select Template",test:"Some content"}
fr : {...},
de:{...},
language : "en", // DEfault to be choosen
init: function() {
var userLang = navigator.language || navigator.userLanguage;
console.log("LANG : "+userLang)
var langToTest = userLang.split('-')[0];
//console.log(langToTest)
this.language = this.getLang(langToTest);
//console.log("new test : "+this.language)
},
 
getLang : function(langToTest){
if (!LANG[langToTest])
{
langToTest = "en";
}
return langToTest;
},

getStr:function(str, defaultStr) {
// console.log('Replace : '+str + " in "+this.language)
var retStr = LANG[this.language][str];
if (typeof retStr != 'undefined'){
return retStr;
} else {
if (typeof defaultStr != 'undefined'){
return defaultStr;
} else {
return LANG['en'][str];
}
}
}
}
 
Pour l'appeler je fais :
LANG.init();
LANG.getStr(MY_CODE_IN_THE_LANG_JSON)
 
Stéphane
 

View solution in original post

2 REPLIES 2

Stephane_fr
Google Developer Expert
Google Developer Expert

Hi Benjamin

 

In Google Wroksapce Add-on you have a specific object to get user local : https://developers.google.com/workspace/add-ons/how-tos/access-user-locale

 

After for the application on my side for an internal I just implemened a javascript code to translate text when needed.

 

var LANG = {
en : {select_template:"Select Template",test:"Some content"}
fr : {...},
de:{...},
language : "en", // DEfault to be choosen
init: function() {
var userLang = navigator.language || navigator.userLanguage;
console.log("LANG : "+userLang)
var langToTest = userLang.split('-')[0];
//console.log(langToTest)
this.language = this.getLang(langToTest);
//console.log("new test : "+this.language)
},
 
getLang : function(langToTest){
if (!LANG[langToTest])
{
langToTest = "en";
}
return langToTest;
},

getStr:function(str, defaultStr) {
// console.log('Replace : '+str + " in "+this.language)
var retStr = LANG[this.language][str];
if (typeof retStr != 'undefined'){
return retStr;
} else {
if (typeof defaultStr != 'undefined'){
return defaultStr;
} else {
return LANG['en'][str];
}
}
}
}
 
Pour l'appeler je fais :
LANG.init();
LANG.getStr(MY_CODE_IN_THE_LANG_JSON)
 
Stéphane
 

Thanks a lot @Stephane_fr!

Top Labels in this Space