perf: use util in OutLayout
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2025-01-21 13:55:20 +01:00
parent 21251a5167
commit 00cea34dde
3 changed files with 21 additions and 20 deletions

View File

@ -1,6 +1,9 @@
<script setup> <script setup>
import quasarLang from 'src/utils/quasarLang';
import { onMounted, computed, ref } from 'vue'; import { onMounted, computed, ref } from 'vue';
import { Dark, Quasar } from 'quasar';
import { Dark } from 'quasar';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import axios from 'axios'; import axios from 'axios';
@ -22,7 +25,6 @@ const { t, locale } = useI18n();
const { copyText } = useClipboard(); const { copyText } = useClipboard();
const { notify } = useNotify(); const { notify } = useNotify();
const langList = import.meta.glob('../../node_modules/quasar/lang/*.js');
const userLocale = computed({ const userLocale = computed({
get() { get() {
return locale.value; return locale.value;
@ -32,13 +34,7 @@ const userLocale = computed({
value = localeEquivalence[value] ?? value; value = localeEquivalence[value] ?? value;
try { quasarLang(value);
langList[`../../node_modules/quasar/lang/${value}.js`]().then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {
//
}
}, },
}); });

View File

@ -2,6 +2,8 @@
import { Dark, Quasar } from 'quasar'; import { Dark, Quasar } from 'quasar';
import { computed } from 'vue'; import { computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { localeEquivalence } from 'src/i18n/index';
import quasarLang from 'src/utils/quasarLang';
const { t, locale } = useI18n(); const { t, locale } = useI18n();
@ -12,18 +14,9 @@ const userLocale = computed({
set(value) { set(value) {
locale.value = value; locale.value = value;
if (value === 'en') value = 'en-GB'; value = localeEquivalence[value] ?? value;
// FIXME: Dynamic imports from absolute paths are not compatible with vite: quasarLang(value);
// https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
try {
const langList = import.meta.glob('../../node_modules/quasar/lang/*.mjs');
langList[`../../node_modules/quasar/lang/${value}.mjs`]().then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {
//
}
}, },
}); });

12
src/utils/quasarLang.js Normal file
View File

@ -0,0 +1,12 @@
const langList = import.meta.glob('../../node_modules/quasar/lang/*.js');
import { Quasar } from 'quasar';
export default function (value) {
try {
langList[`../../node_modules/quasar/lang/${value}.js`]().then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {
//
}
}