Get the language module out of spot.js
This commit is contained in:
+13
-21
@@ -1,29 +1,21 @@
|
||||
import Css from './../styles/spot.scss';
|
||||
|
||||
//Masks
|
||||
//Librairies
|
||||
import Lang from './lang.js';
|
||||
import Spot from './spot.js';
|
||||
//import Project from './page.project.js';
|
||||
//import Upload from './page.upload.js';
|
||||
//import Admin from './page.admin.js';
|
||||
|
||||
//let oProject = new Project(oSpot);
|
||||
//oSpot.addPage('project', oProject);
|
||||
|
||||
//let oUpload = new Upload(oSpot);
|
||||
//oSpot.addPage('upload', oUpload);
|
||||
|
||||
//let oAdmin = new Admin(oSpot);
|
||||
//oSpot.addPage('admin', oAdmin);
|
||||
|
||||
//$(() => {oSpot.init();});
|
||||
|
||||
import { createApp } from 'vue';
|
||||
import SpotVue from '../Spot.vue';
|
||||
|
||||
const appConfigElement = document.getElementById('app-config');
|
||||
const appConfig = appConfigElement ? JSON.parse(appConfigElement.textContent || '{}') : {};
|
||||
const oSpot = new Spot(appConfig);
|
||||
//Style
|
||||
import Css from './../styles/spot.scss';
|
||||
|
||||
//App Configuration from PHP
|
||||
const appConfig = JSON.parse(document.getElementById('app-config').textContent);
|
||||
|
||||
//Instances
|
||||
const oLang = new Lang({translations: appConfig.consts.lang, prefix: appConfig.consts.lang_prefix});
|
||||
const oSpot = new Spot(appConfig, oLang);
|
||||
|
||||
//Mount app
|
||||
const oSpotVue = createApp(SpotVue);
|
||||
oSpotVue.provide('spot', oSpot);
|
||||
oSpotVue.provide('lang', oLang);
|
||||
oSpotVue.mount('#container');
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ export default class Lang {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
lang(key = '', params = []) {
|
||||
get(key = '', params = []) {
|
||||
if(key === '') return '';
|
||||
|
||||
const normalizedParams = Array.isArray(params) ? params : [params];
|
||||
@@ -24,7 +24,7 @@ export default class Lang {
|
||||
|
||||
parse(message = '') {
|
||||
if(this.prefix && typeof message === 'string' && message.startsWith(this.prefix)) {
|
||||
return this.lang(message.slice(this.prefix.length));
|
||||
return this.get(message.slice(this.prefix.length));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
+5
-14
@@ -1,19 +1,14 @@
|
||||
import { copyArray, getElem, setElem } from './common.js';
|
||||
import Lang from './lang.js';
|
||||
|
||||
export default class Spot {
|
||||
|
||||
constructor(asGlobals) {
|
||||
constructor(asGlobals, oLang) {
|
||||
this.consts = asGlobals.consts;
|
||||
this.consts.hash_sep = '-';
|
||||
this.consts.title = 'Spotty';
|
||||
this.consts.default_page = 'project';
|
||||
//this.consts.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || this.consts.default_timezone;
|
||||
|
||||
this.translator = new Lang({
|
||||
translations: this.consts.lang || {},
|
||||
prefix: this.consts.lang_prefix || ''
|
||||
});
|
||||
this.lang = oLang;
|
||||
|
||||
this.pages = {};
|
||||
|
||||
@@ -112,7 +107,7 @@ export default class Spot {
|
||||
else {
|
||||
let oResponse = await oRequest.json();
|
||||
bLoading = false;
|
||||
oResponse.desc = this.translator.parse(oResponse.desc);
|
||||
oResponse.desc = this.lang.parse(oResponse.desc);
|
||||
|
||||
if(oResponse.result == this.consts.error) return Promise.reject(oResponse.desc);
|
||||
else return oResponse.data;
|
||||
@@ -124,10 +119,6 @@ export default class Spot {
|
||||
}
|
||||
}
|
||||
|
||||
lang(sKey, asParams = []) {
|
||||
return this.translator.lang(sKey, asParams);
|
||||
}
|
||||
|
||||
isMobile() {
|
||||
const mobileElem = document.getElementById('mobile');
|
||||
return !!mobileElem && getComputedStyle(mobileElem).display !== 'none';
|
||||
@@ -295,8 +286,8 @@ export default class Spot {
|
||||
iTimeMinutes = Math.floor(iHours * 4) * 15; //Round down to the closest 15 minutes
|
||||
}
|
||||
return '~ '
|
||||
+(iTimeDays>0?(iTimeDays+(iTimeDays%2==0?'':'½')+' '+this.lang(iTimeDays>1?'unit_days':'unit_day')):'') //Days
|
||||
+((iTimeHours>0 || iTimeDays==0)?iTimeHours+this.lang('unit_hour'):'') //Hours
|
||||
+(iTimeDays>0?(iTimeDays+(iTimeDays%2==0?'':'½')+' '+this.lang.get(iTimeDays>1?'unit_days':'unit_day')):'') //Days
|
||||
+((iTimeHours>0 || iTimeDays==0)?iTimeHours+this.lang.get('unit_hour'):'') //Hours
|
||||
+((iTimeDays>0 || iTimeMinutes==0)?'':iTimeMinutes) //Minutes
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user