added language switcher and defualt language finder

This commit is contained in:
MathMan05 2024-11-01 13:31:15 -05:00
parent 3fb4920ab0
commit 9a7c70bd55
3 changed files with 50 additions and 21 deletions

View file

@ -105,6 +105,27 @@ class I18n{
return trans;
}
}
static options(){
return ["en","ru"]
}
static setLanguage(lang:string){
if(this.options().indexOf(userLocale)!==-1){
localStorage.setItem("lang",lang);
I18n.create("/translations/en.json",lang);
}
}
}
I18n.create("/translations/en.json","en")
let userLocale = navigator.language.slice(0,2) || "en";
if(I18n.options().indexOf(userLocale)===-1){
userLocale="en";
}
const storage=localStorage.getItem("lang");
if(storage){
userLocale=storage;
}else{
localStorage.setItem("lang",userLocale)
}
I18n.create("/translations/en.json",userLocale);
export{I18n};

View file

@ -1243,25 +1243,7 @@ class Localuser{
{ initColor: userinfos.accent_color }
);
}
{
const box=tas.addCheckboxInput(I18n.getTranslation("localuser.enableEVoice"),()=>{},{initState:Boolean(localStorage.getItem("Voice enabled"))});
box.onchange=(e)=>{
if(e){
if(confirm(I18n.getTranslation("localuser.VoiceWarning"))){
localStorage.setItem("Voice enabled","true")
}else{
box.value=true;
const checkbox=box.input.deref();
if(checkbox){
checkbox.checked=false;
}
}
}else{
localStorage.removeItem("Voice enabled");
}
}
}
}
{
const update=settings.addButton(I18n.getTranslation("localuser.updateSettings"))
@ -1434,6 +1416,31 @@ class Localuser{
}
});
});
security.addSelect(I18n.getTranslation("localuser.language"),(e)=>{
I18n.setLanguage(I18n.options()[e]);
},I18n.options(),{
defaultIndex:I18n.options().indexOf(I18n.lang)
});
{
const box=security.addCheckboxInput(I18n.getTranslation("localuser.enableEVoice"),()=>{},{initState:Boolean(localStorage.getItem("Voice enabled"))});
box.onchange=(e)=>{
if(e){
if(confirm(I18n.getTranslation("localuser.VoiceWarning"))){
localStorage.setItem("Voice enabled","true")
}else{
box.value=true;
const checkbox=box.input.deref();
if(checkbox){
checkbox.checked=false;
}
}
}else{
localStorage.removeItem("Voice enabled");
}
}
}
};
genSecurity();
}

View file

@ -303,7 +303,8 @@
"saveToken":"Save token to localStorage",
"noToken":"Don't know token so can't save it to localStorage, sorry",
"advancedBot":"Advanced Bot Settings",
"botInviteCreate":"Bot Invite Creator"
"botInviteCreate":"Bot Invite Creator",
"language":"Language:"
},
"instanceStats":{
"name":"Instance stats: $1",
@ -370,5 +371,5 @@
"retrying":"Retrying...",
"unableToConnect":"Unable to connect to the Spacebar server. Please try logging out and back in."
},
"ru": "./ru.json"
"ru": "/translations/ru.json"
}