fix: intl for ESS

This commit is contained in:
Jean-Baptiste Pasquier 2021-04-08 20:22:39 +02:00
parent a5ede42a91
commit e2c9da2459
7 changed files with 1289 additions and 752 deletions

1892
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,9 @@
"cypress:info": "cypress info",
"test": "cypress run"
},
"browserslist": [
"last 2 Chrome versions"
],
"release": {
"branches": [
"master"
@ -49,7 +52,7 @@
"cross-env": "^7.0.3",
"fs-extra": "^9.0.1",
"normalize.css": "^8.0.1",
"parcel-bundler": "^1.12.4",
"parcel-bundler": "^1.12.5",
"pug": "^3.0.0",
"rimraf": "^2.7.1",
"sass": "^1.29.0"

View File

@ -32,13 +32,7 @@
"circlesBrowse": "Browse circles",
"circleCreate": "Create circle",
"messages": "Messages",
"search": "Search",
"republiqueESS": {
"home": "Home",
"contribute": "Contribute",
"thematics": "Thematics",
"community": "Community"
}
"search": "Search"
},
"about": {
"title": "About",
@ -131,10 +125,7 @@
"subTitle": "Members :"
},
"extensions": {
"associated": "Associated circle",
"republiqueESS": {
"associatedThematic": "Associated thematic"
}
"associated": "Associated circle"
}
},
"communities": {

View File

@ -32,13 +32,7 @@
"circlesBrowse": "Examinar los círculos",
"circleCreate": "Crea un círculo.",
"messages": "Mensajes",
"search": "Buscar",
"republiqueESS": {
"home": "Hogar",
"contribute": "Contribuir",
"thematics": "Temáticas",
"community": "Comunidad"
}
"search": "Buscar"
},
"about": {
"title": "Acerca de",
@ -131,10 +125,7 @@
"subTitle": "Miembrxs: "
},
"extensions": {
"associated": "Círculo asociado",
"republiqueESS": {
"associatedThematic": "Temática asociada"
}
"associated": "Círculo asociado"
}
},
"communities": {

View File

@ -9,9 +9,7 @@
},
"menuLeft": {
"emptyCircleProjectContact": {
"empty": "Il n'y a aucun résultat dans cette section.",
"project": "projet",
"circle": "cercle"
"empty": "Il n'y a aucun résultat dans cette section."
},
"contact": {
"create": "Retrouve tes contacts sur",
@ -32,13 +30,7 @@
"circlesBrowse": "Parcourir les cercles",
"circleCreate": "Créer un cercle",
"messages": "Messages",
"search": "Rechercher",
"republiqueESS": {
"home": "Accueil",
"contribute": "Contribuer",
"thematics": "Thématiques",
"community": "Communauté"
}
"search": "Rechercher"
},
"about": {
"title": "A propos",
@ -131,10 +123,7 @@
"subTitle": "Membres :"
},
"extensions": {
"associated": "Cercle associé",
"republiqueESS": {
"associatedThematic": "Thématique associée"
}
"associated": "Cercle associé"
}
},
"communities": {

View File

@ -6,27 +6,27 @@ class JsI18n {
constructor() {
this.locale = ""; //Current locale
this.locales = new Array(); //Available locales
this.overwrites = new Array();
this.defaultLocale = "fr";
}
/*
Method for automatically detecting the language, does not work in every browser.
*/
detectLanguage() {
async detectLanguage() {
const customLangs = document.querySelectorAll('hubl-lang');
if (customLangs) {
for (let lang of customLangs) {
let name = lang.getAttribute('lang'),
file = lang.getAttribute('file');
if(window.hubl.intl.locales[name.toString()] == undefined) {
return fetch(file).then((result) => {
let result = await fetch(file);
if (result.ok) {
result.json().then(e => {
window.hubl.intl.addLocale(name, e);
});
let json = await result.json();
if(this.overwrites[name.toString()] != undefined) {
this.mergeDeep(this.overwrites[name.toString()], json);
} else {
this.overwrites[name.toString()] = json;
}
window.hubl.intl.resumeDetection();
});
}
}
}
@ -52,6 +52,30 @@ class JsI18n {
}
};
isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
mergeDeep(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (this.isObject(target) && this.isObject(source)) {
for (const key in source) {
if (this.isObject(source[key])) {
if (!target[key]) Object.assign(target, {
[key]: {}
});
this.mergeDeep(target[key], source[key]);
} else {
Object.assign(target, {
[key]: source[key]
});
}
}
}
return this.mergeDeep(target, ...sources);
}
/*
Translates tag contents and
attributes depending on the
@ -145,11 +169,13 @@ class JsI18n {
if the locale is already defined.
*/
addLocale(locale, translations) {
if (this.overwrites[locale.toString()] != undefined) {
this.mergeDeep(translations, this.overwrites[locale.toString()]);
}
this.locales[locale.toString()] = translations;
}
fetchLocale(locale) {
if(this.locales[locale.toString()] == undefined) {
return fetch(`/locales/${locale}.json`).then((result) => {
if (result.ok) {
result.json().then(e => {
@ -157,9 +183,6 @@ class JsI18n {
});
}
});
} else {
return (new Promise()).resolve();
}
}
/*

View File

@ -131,10 +131,10 @@ nav#main__menu {
.menu-admin {
position: absolute;
z-index: 3016;
left: 78px;
left: 15%;
top: 36px;
text-align: end;
width: 64%;
width: 80%;
@media (max-width: 768px) {
width: 100%;