Dynamically load language files (#446)

This commit is contained in:
Darko Gjorgjijoski
2025-08-28 15:19:51 +02:00
committed by GitHub
parent 32f7bc053a
commit a40bf5840d
10 changed files with 154 additions and 59 deletions

View File

@@ -65,7 +65,8 @@ export default {
}
if(typeof res.data.profile_language === 'string') {
global.locale.value = res.data.profile_language
// Use dynamic language loading instead of direct assignment
await window.loadLanguage(res.data.profile_language)
}
let dbstep = parseInt(res.data.profile_complete)

View File

@@ -27,6 +27,8 @@
<BaseButton
v-show="!isFetchingInitialData"
:loading="isChangingLanguage"
:disabled="isChangingLanguage"
@click="next"
>
{{ $t('wizard.continue') }}
@@ -43,12 +45,11 @@
import { ref, onMounted } from 'vue'
import { useInstallationStore } from '@/scripts/admin/stores/installation.js'
const { global } = window.i18n
const emit = defineEmits(['next'])
let isFetchingInitialData = ref(false)
let isSaving = ref(false)
let isChangingLanguage = ref(false)
let languages = ref([])
let currentLanguage = 'en'
@@ -75,11 +76,19 @@ function next() {
isSaving.value = false
}
function changeLanguage(event){
if(typeof global.locale !== 'string') {
global.locale.value = event
async function changeLanguage(event) {
if (!event) return
isChangingLanguage.value = true
try {
// Dynamically load the selected language
await window.loadLanguage(event)
currentLanguage.value = event
} catch (error) {
console.error('Failed to change language:', error)
} finally {
isChangingLanguage.value = false
}
}
</script>

View File

@@ -200,6 +200,9 @@ async function updateUserData() {
// Update Language if changed
if (userStore.currentUserSettings.language !== userForm.language) {
// Load the new language dynamically before updating settings
await window.loadLanguage(userForm.language)
await userStore.updateUserSettings({
settings: {
language: userForm.language,

View File

@@ -105,7 +105,7 @@
class="w-full"
/>
</BaseInputGroup>
<BaseInputGroup
:label="$t('settings.preferences.time_format')"
:content-loading="isFetchingInitialData"
@@ -378,6 +378,12 @@ async function updatePreferencesData() {
isSaving.value = true
delete data.settings.link_expiry_days
// If language is being changed, load it dynamically first
if (companyStore.selectedCompanySettings.language !== settingsForm.language) {
await window.loadLanguage(settingsForm.language)
}
let res = await companyStore.updateCompanySettings({
data: data,
message: 'settings.preferences.updated_message',