feat: VnLv

This commit is contained in:
Javier Segarra 2024-05-20 09:13:22 +02:00
parent ea92e13b78
commit 155a0b6440
2 changed files with 66 additions and 2 deletions

View File

@ -37,8 +37,9 @@ module.exports = configure(function (/* ctx */) {
'quasar',
'quasar.defaults',
'customQTh',
'customQInput',
'customQSelect',
// 'customQInput',
// 'customQSelect',
'vnTranslate',
],
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css

63
src/boot/vnTranslate.js Normal file
View File

@ -0,0 +1,63 @@
import { boot } from 'quasar/wrappers';
import i18n from 'src/i18n';
import { QInput, QSelect } from 'quasar';
import VnLv from 'src/components/ui/VnLv.vue';
const VALID_QUASAR_ELEMENTS = [QSelect.name, QInput.name];
const VALID_VN_ELEMENTS = [VnLv.__name];
export default boot(({ app }) => {
// Usar vue-i18n en la aplicación
app.use(i18n);
app.mixin({
mounted() {
this.handleElement(this.$el);
},
methods: {
translateLabel(labelElement) {
if (labelElement) {
const labelKey = labelElement.textContent.trim();
labelElement.textContent = this.$t(labelKey);
}
},
handleElement(el) {
if (!el) return;
if (
this.$options?.__name &&
VALID_VN_ELEMENTS.includes(this.$options.__name)
) {
this.translateLabel(this.$el.querySelector('.label'));
// const labelElement = this.$el.querySelector('.label');
// if (labelElement) {
// const labelKey = labelElement.textContent.trim();
// labelElement.textContent = this.$t(labelKey);
// }
}
// Recorrer los elementos hijos
if (VALID_QUASAR_ELEMENTS.includes(this.$options?.name)) {
const _children = el.children || [];
const childrens = Array.from(_children).filter(
(child) =>
child.tagName === 'DIV' &&
child.classList.contains('q-field__inner')
);
for (const child of childrens) {
const input = child.querySelector('input');
if (
VALID_QUASAR_ELEMENTS.includes(
input?.__vueParentComponent?.type?.name
)
) {
this.translateLabel(child.querySelector('.q-field__label'));
// const labelElement = child.querySelector('.q-field__label');
// if (labelElement) {
// const labelKey = labelElement.textContent.trim();
// labelElement.textContent = this.$t(labelKey);
// }
}
}
}
},
},
});
});