|
|
|
|
@ -1,62 +1,51 @@ |
|
|
|
|
import {usePlatformConfig} from "../store/platformConfig"; |
|
|
|
|
import {useSecurityStore} from "../store/securityStore"; |
|
|
|
|
import {useCidReqStore} from "../store/cidReq"; |
|
|
|
|
import {computed, ref} from "vue"; |
|
|
|
|
import { usePlatformConfig } from "../store/platformConfig" |
|
|
|
|
import { useSecurityStore } from "../store/securityStore" |
|
|
|
|
import { useCidReqStore } from "../store/cidReq" |
|
|
|
|
import { useCourseSettings } from "../store/courseSettingStore" |
|
|
|
|
import { computed, ref, watch } from "vue" |
|
|
|
|
|
|
|
|
|
export function useLocale() { |
|
|
|
|
const platformConfigStore = usePlatformConfig() |
|
|
|
|
const securityStore = useSecurityStore() |
|
|
|
|
const cidReqStore = useCidReqStore() |
|
|
|
|
const courseSettingsStore = useCourseSettings() |
|
|
|
|
|
|
|
|
|
const localeList = computed(() => { |
|
|
|
|
const list = {}; |
|
|
|
|
|
|
|
|
|
const platformLocale = platformConfigStore.getSetting('language.platform_language') |
|
|
|
|
|
|
|
|
|
if (platformLocale) { |
|
|
|
|
list['platform_lang'] = platformLocale |
|
|
|
|
} |
|
|
|
|
const appLocale = ref(document.querySelector('html').lang) |
|
|
|
|
|
|
|
|
|
const userLocale = securityStore.user ? securityStore.user.locale : null |
|
|
|
|
|
|
|
|
|
if (userLocale) { |
|
|
|
|
list['user_profil_lang'] = userLocale |
|
|
|
|
watch(() => { |
|
|
|
|
return cidReqStore.course ? cidReqStore.course.id : null |
|
|
|
|
}, (newId, oldId) => { |
|
|
|
|
if (newId) { |
|
|
|
|
courseSettingsStore.loadCourseSettings(newId) |
|
|
|
|
} |
|
|
|
|
}, { immediate: true }) |
|
|
|
|
|
|
|
|
|
const courseLocale = cidReqStore.course ? cidReqStore.course.courseLanguage : null |
|
|
|
|
|
|
|
|
|
if (courseLocale) { |
|
|
|
|
list['course_lang'] = courseLocale |
|
|
|
|
const localeList = computed(() => { |
|
|
|
|
const list = {} |
|
|
|
|
list['platform_lang'] = platformConfigStore.getSetting('language.platform_language') |
|
|
|
|
list['user_profil_lang'] = securityStore.user ? securityStore.user.locale : null |
|
|
|
|
|
|
|
|
|
let courseLang = null |
|
|
|
|
if (courseSettingsStore.getSetting('show_course_in_user_language') === '1' && securityStore.user && securityStore.user.locale) { |
|
|
|
|
courseLang = securityStore.user.locale |
|
|
|
|
} else if (cidReqStore.course) { |
|
|
|
|
courseLang = cidReqStore.course.courseLanguage |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @todo check language from request
|
|
|
|
|
//list['user_selected_lang'] = ?
|
|
|
|
|
list['course_lang'] = courseLang |
|
|
|
|
|
|
|
|
|
return list |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const priorityList = [ |
|
|
|
|
'language_priority_1', |
|
|
|
|
'language_priority_2', |
|
|
|
|
'language_priority_3', |
|
|
|
|
'language_priority_4', |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const appLocale = ref('') |
|
|
|
|
|
|
|
|
|
for (const setting of priorityList) { |
|
|
|
|
const priority = platformConfigStore.getSetting(`language.${setting}`) |
|
|
|
|
|
|
|
|
|
if (priority && localeList.value[priority]) { |
|
|
|
|
appLocale.value = localeList.value[priority] |
|
|
|
|
|
|
|
|
|
break |
|
|
|
|
watch(localeList, (newLocaleList) => { |
|
|
|
|
const priorityList = ['language_priority_1', 'language_priority_2', 'language_priority_3', 'language_priority_4'] |
|
|
|
|
for (const priority of priorityList) { |
|
|
|
|
const setting = platformConfigStore.getSetting(`language.${priority}`) |
|
|
|
|
if (setting && newLocaleList[setting]) { |
|
|
|
|
appLocale.value = newLocaleList[setting] |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!appLocale.value) { |
|
|
|
|
appLocale.value = document.querySelector('html').lang |
|
|
|
|
} |
|
|
|
|
}, { immediate: true }) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
appLocale |
|
|
|
|
|