Skip to content

Commit

Permalink
fix locale id fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
crocsg committed Jul 4, 2024
1 parent 90d855c commit 8f396bd
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions src/components/localestring.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,41 @@
import locales from './locales.js';
class LocaleString
{
constructor ()
{
class LocaleString {
constructor() {
this.locale = locales;
this.selectedlocale = 'fr'
console.log ("LocaleString constructor");

this.selectedlocale = 'fr'; // select fr as default
}
getLocaleString (id)
{

if(id in this.locale[this.selectedlocale].data)
getLocaleString(id) {

if (id in this.locale[this.selectedlocale].data)
return (this.locale[this.selectedlocale].data[id])
console.log ("invalid id " + id + " locale " + this.selectedlocale)

return ("Unknown locale string ???")
console.log("invalid id " + id + " locale " + this.selectedlocale)

//fallback to en locale
if (id in this.locale["en"].data)
return (this.locale["en"].data[id])
// definetly bad id
return ("Unknown locale id ???")
}
getLocaleDir (dir)
{
getLocaleDir(dir) {
return (this.locale[this.selectedlocale].dir)
}
getBrailleReverse()
{
getBrailleReverse() {
return (this.locale[this.selectedlocale].reverse)
}
setLocaleCode (locale)
{
setLocaleCode(locale) {
if (locale in this.locale)
this.selectedlocale = locale;

}
getLocaleCode ()
{
getLocaleCode() {
return (this.selectedlocale)
}
getLocaleList ()
{
getLocaleList() {
let list = [];
for (let locale in this.locale)
{
list.push (this.locale[locale]);

}
for (let locale in this.locale) {
list.push(this.locale[locale]);

}
return (list);
}
};
Expand Down

0 comments on commit 8f396bd

Please sign in to comment.