mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-15 14:02:17 +00:00
update(FHC_JS_DATA_STORAGE_OBJECT/Sprachen.js): adds server_languages and their locale to FHC_JS_DATA_STORAGE_OBJECT and updates Sprachen.js accordingly
This commit is contained in:
@@ -87,21 +87,28 @@ function generateCSSsInclude($CSSs)
|
||||
*/
|
||||
function generateJSDataStorageObject($indexPage, $calledPath, $calledMethod)
|
||||
{
|
||||
$ci =& get_instance();
|
||||
$ci->load->model('system/Sprache_model','SpracheModel');
|
||||
$server_language = getData($ci->SpracheModel->loadWhere(['content' => true]));
|
||||
$server_language = array_map(function($language){
|
||||
return ['sprache'=>$language->sprache, 'locale'=>$language->locale, 'bezeichnung'=>$language->bezeichnung[$language->index-1]];
|
||||
}, $server_language);
|
||||
$user_language = getUserLanguage();
|
||||
|
||||
// default locale
|
||||
//user_locale: "'.Locale::DEFAULT_LOCALE.'",
|
||||
$FHC_JS_DATA_STORAGE_OBJECT = array(
|
||||
'app_root' => APP_ROOT,
|
||||
'ci_router' => $indexPage,
|
||||
'called_path' => $calledPath,
|
||||
'called_method' => $calledMethod,
|
||||
'server_languages' => $server_language,
|
||||
'user_language' => $user_language,
|
||||
'timezone' => date_default_timezone_get(),
|
||||
);
|
||||
|
||||
$toPrint = "\n";
|
||||
$toPrint .= '<script type="text/javascript">';
|
||||
$toPrint .= '
|
||||
var FHC_JS_DATA_STORAGE_OBJECT = {
|
||||
app_root: "'.APP_ROOT.'",
|
||||
ci_router: "'.$indexPage.'",
|
||||
called_path: "'.$calledPath.'",
|
||||
called_method: "'.$calledMethod.'",
|
||||
user_language: "'.$user_language.'",
|
||||
timezone: "'.date_default_timezone_get().'",
|
||||
};';
|
||||
var FHC_JS_DATA_STORAGE_OBJECT = '.json_encode($FHC_JS_DATA_STORAGE_OBJECT).';';
|
||||
$toPrint .= "\n";
|
||||
$toPrint .= '</script>';
|
||||
$toPrint .= "\n\n";
|
||||
|
||||
@@ -102,9 +102,9 @@ export default {
|
||||
dayText(){
|
||||
if(!this.size || !this.day)return {};
|
||||
return {
|
||||
heading: this.day.toLocaleString(this.$p.user_language_locale_identifier.value, { dateStyle: 'short' }),
|
||||
tag: this.day.toLocaleString(this.$p.user_language_locale_identifier.value, { weekday: this.size < 2 ? 'narrow' : (this.size < 3 ? 'short' : 'long') }),
|
||||
datum: this.day.toLocaleString(this.$p.user_language_locale_identifier.value, [{ day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { dateStyle: 'short' }][this.size]),
|
||||
heading: this.day.toLocaleString(this.$p.user_locale.value, { dateStyle: 'short' }),
|
||||
tag: this.day.toLocaleString(this.$p.user_locale.value, { weekday: this.size < 2 ? 'narrow' : (this.size < 3 ? 'short' : 'long') }),
|
||||
datum: this.day.toLocaleString(this.$p.user_locale.value, [{ day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { dateStyle: 'short' }][this.size]),
|
||||
}
|
||||
},
|
||||
dayGridStyle() {
|
||||
|
||||
@@ -17,7 +17,7 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
title() {
|
||||
return this.focusDate.format({month: ['short','long','long','long'][this.size], year: 'numeric'}, this.$p.user_language_locale_identifier.value);
|
||||
return this.focusDate.format({month: ['short','long','long','long'][this.size], year: 'numeric'}, this.$p.user_locale.value);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -32,7 +32,7 @@ export default {
|
||||
if (!this.size || !this.weeks[0]?.days) return {};
|
||||
let dayTextMap ={};
|
||||
this.weeks[0].days.forEach((day)=>{
|
||||
dayTextMap[day] = day.toLocaleString(this.$p.user_language_locale_identifier.value, { weekday: this.size < 1 ? 'narrow' : (this.size < 3 ? 'short' : 'long') });
|
||||
dayTextMap[day] = day.toLocaleString(this.$p.user_locale.value, { weekday: this.size < 1 ? 'narrow' : (this.size < 3 ? 'short' : 'long') });
|
||||
});
|
||||
return dayTextMap;
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@ export default {
|
||||
return this.focusDate.format({year: 'numeric'});
|
||||
},
|
||||
months() {
|
||||
return this.monthIndices.map(i => (new Date(0, i, 1)).toLocaleString(this.$p.user_language_locale_identifier.value, {month: this.size < 2 ? 'short' : 'long'}));
|
||||
return this.monthIndices.map(i => (new Date(0, i, 1)).toLocaleString(this.$p.user_locale.value, {month: this.size < 2 ? 'short' : 'long'}));
|
||||
}
|
||||
},
|
||||
template: `
|
||||
|
||||
@@ -61,9 +61,9 @@ export default {
|
||||
let dayTextMap ={};
|
||||
this.days.forEach((day)=>{
|
||||
dayTextMap[day] = {
|
||||
heading: day.toLocaleString(this.$p.user_language_locale_identifier.value, { dateStyle: 'short' }),
|
||||
tag: day.toLocaleString(this.$p.user_language_locale_identifier.value, { weekday: this.size < 2 ? 'narrow' : (this.size < 3 ? 'short' : 'long') }),
|
||||
datum: day.toLocaleString(this.$p.user_language_locale_identifier.value, [{ day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { dateStyle: 'short' }][this.size]),
|
||||
heading: day.toLocaleString(this.$p.user_locale.value, { dateStyle: 'short' }),
|
||||
tag: day.toLocaleString(this.$p.user_locale.value, { weekday: this.size < 2 ? 'narrow' : (this.size < 3 ? 'short' : 'long') }),
|
||||
datum: day.toLocaleString(this.$p.user_locale.value, [{ day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { day: 'numeric', month: 'numeric' }, { dateStyle: 'short' }][this.size]),
|
||||
};
|
||||
});
|
||||
return dayTextMap;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
export default {
|
||||
data(){
|
||||
return {
|
||||
allActiveLanguages: null,
|
||||
sprachenTranslation:null,
|
||||
allActiveLanguages: FHC_JS_DATA_STORAGE_OBJECT.server_languages,
|
||||
}
|
||||
},
|
||||
emits: ['languageChanged'],
|
||||
methods:{
|
||||
changeLanguage: function(lang){
|
||||
if(this.allActiveLanguages.some(l => l === lang))
|
||||
if(this.allActiveLanguages.some(l => l.sprache === lang))
|
||||
{
|
||||
this.$p.setLanguage(lang, this.$fhcApi)
|
||||
.then(res => res.data)
|
||||
@@ -18,25 +17,11 @@ export default {
|
||||
})
|
||||
}
|
||||
},
|
||||
getSprachenBezeichnung: function(lang){
|
||||
if (!Array.isArray(this.sprachenTranslation) || this.sprachenTranslation.length == 0) return;
|
||||
return this.sprachenTranslation.find(s=>s.sprache == lang)?.bezeichnung;
|
||||
},
|
||||
},
|
||||
mounted(){
|
||||
this.$fhcApi.factory.phrasen.getActiveDbLanguages()
|
||||
.then(res => res.data)
|
||||
.then(
|
||||
(langs) => {
|
||||
this.allActiveLanguages = langs.map(l=>l.sprache);
|
||||
this.sprachenTranslation = langs;
|
||||
}
|
||||
);
|
||||
},
|
||||
template:/*html*/`
|
||||
<div class="container">
|
||||
<div class="row justify-content-center align-items-center flex-nowrap overflow-hidden">
|
||||
<button v-for="lang in allActiveLanguages" @click.prevent="changeLanguage(lang)" class="col text-white fhc-entry btn text-center w-100" :selected="$p.user_language.value==lang?'':null">{{getSprachenBezeichnung(lang)}}</button>
|
||||
<button v-for="lang in allActiveLanguages" @click.prevent="changeLanguage(lang.sprache)" class="col text-white fhc-entry btn text-center w-100" :selected="$p.user_language.value==lang.sprache?'':null">{{lang.bezeichnung}}</button>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
|
||||
@@ -3,13 +3,9 @@ import FhcApi from './FhcApi.js';
|
||||
const categories = Vue.reactive({});
|
||||
const loadingModules = {};
|
||||
let user_language = Vue.ref(FHC_JS_DATA_STORAGE_OBJECT.user_language);
|
||||
let user_language_locale_identifier = Vue.computed(()=>{
|
||||
if(!user_language.value) return undefined;
|
||||
switch(user_language.value){
|
||||
case 'German': return 'de-AT';
|
||||
case 'English': return 'en-GB';
|
||||
default: return undefined;
|
||||
}
|
||||
let user_locale = Vue.computed(()=>{
|
||||
if(!user_language.value) return null;
|
||||
return FHC_JS_DATA_STORAGE_OBJECT.server_languages.find(language => language.sprache == user_language.value).locale;
|
||||
});
|
||||
|
||||
function extractCategory(obj, category) {
|
||||
@@ -30,7 +26,7 @@ function getValueForLoadedPhrase(category, phrase, params) {
|
||||
|
||||
const phrasen = {
|
||||
user_language,
|
||||
user_language_locale_identifier,
|
||||
user_locale,
|
||||
setLanguage(language, api) {
|
||||
const catArray = Object.keys(categories)
|
||||
return api.factory.phrasen.setLanguage(catArray, language).then(res => {
|
||||
@@ -93,7 +89,7 @@ export default {
|
||||
loadCategory: cat => phrasen.loadCategory.call(app, cat),
|
||||
setLanguage: phrasen.setLanguage,
|
||||
user_language: user_language,
|
||||
user_language_locale_identifier: user_language_locale_identifier,
|
||||
user_locale,
|
||||
t_ref: phrasen.t_ref
|
||||
};
|
||||
app.provide('$p', app.config.globalProperties.$p);
|
||||
|
||||
Reference in New Issue
Block a user