0
0
Fork 0

fix: refs #4774 fix translations

This commit is contained in:
Carlos Satorres 2024-10-22 10:37:54 +02:00
parent 4e8ffacea2
commit 61bbeb7012
6 changed files with 75 additions and 45 deletions

View File

@ -95,6 +95,7 @@ defineExpose({
getChanges, getChanges,
formData, formData,
vnPaginateRef, vnPaginateRef,
resetData,
}); });
onBeforeRouteLeave((to, from, next) => { onBeforeRouteLeave((to, from, next) => {

View File

@ -817,6 +817,11 @@ export default {
hasToSendMail: 'Send check-ins by email', hasToSendMail: 'Send check-ins by email',
departmentRemoved: 'Department removed', departmentRemoved: 'Department removed',
}, },
translations: {
pageTitles: {
translations: 'Translations',
},
},
worker: { worker: {
pageTitles: { pageTitles: {
workers: 'Workers', workers: 'Workers',
@ -826,7 +831,7 @@ export default {
notifications: 'Notifications', notifications: 'Notifications',
workerCreate: 'New worker', workerCreate: 'New worker',
department: 'Department', department: 'Department',
TranslationsVn: 'Translations', translations: 'Translations',
}, },
list: { list: {
name: 'Name', name: 'Name',

View File

@ -819,9 +819,10 @@ export default {
hasToSendMail: 'Enviar fichadas por mail', hasToSendMail: 'Enviar fichadas por mail',
departmentRemoved: 'Departamento eliminado', departmentRemoved: 'Departamento eliminado',
}, },
TranslationsVn: { translations: {
OriginalLanguage: 'Idioma Original', pageTitles: {
SecondLanguage: 'Idioma Secundario', translations: 'Traducciones',
},
}, },
worker: { worker: {
pageTitles: { pageTitles: {
@ -832,7 +833,7 @@ export default {
notifications: 'Notificaciones', notifications: 'Notificaciones',
workerCreate: 'Nuevo trabajador', workerCreate: 'Nuevo trabajador',
department: 'Departamentos', department: 'Departamentos',
TranslationsVn: 'Traducciones', translations: 'Traducciones',
}, },
list: { list: {
name: 'Nombre', name: 'Nombre',

View File

@ -277,6 +277,7 @@ globals:
medical: Mutual medical: Mutual
RouteExtendedList: Router RouteExtendedList: Router
wasteRecalc: Waste recaclulate wasteRecalc: Waste recaclulate
translations: Translations
supplier: Supplier supplier: Supplier
created: Created created: Created
worker: Worker worker: Worker

View File

@ -281,6 +281,7 @@ globals:
serial: Facturas por serie serial: Facturas por serie
medical: Mutua medical: Mutua
wasteRecalc: Recalcular mermas wasteRecalc: Recalcular mermas
translations: Traducciones
supplier: Proveedor supplier: Proveedor
created: Fecha creación created: Fecha creación
worker: Trabajador worker: Trabajador

View File

@ -13,78 +13,79 @@ const { t } = useI18n();
const columns = computed(() => [ const columns = computed(() => [
{ {
align: 'left', align: 'left',
name: 'companyFk', name: primaryKey,
label: t('company18n'), label: t('primaryKey'),
chip: {
condition: () => true,
},
isId: true,
}, },
{ {
align: 'left', align: 'left',
name: 'footnotes', name: field,
label: t('defaultLang(en)'), label: t('defaultLang(en)'),
component: 'input',
}, },
{ {
align: 'left', align: 'left',
name: 'secondLang', name: 'secondLang',
label: t('secondLang'), label: t('secondLang'),
component: 'input',
}, },
]); ]);
const tableRef = ref({}); const tableRef = ref({});
const langs = ref([]); const langs = ref([]);
const pk = ref('companyFk'); const tables = ref([]);
const value = ref('footnotes');
const lang = ref('es'); const lang = ref('es');
const primaryKey = computed(() => table.value.primaryKey);
const field = computed(() => table.value.field);
const table = ref();
const originalData = ref(); const originalData = ref();
const englishData = ref(); const url = computed(() => table.value?.tableName + 's');
// onMounted(() => { // onMounted(() => {
// loadTable(); // loadTable();
// }); // });
async function loadTable() { async function loadTable() {
console.log('lang.value.code: ', lang.value);
const data = tableRef.value.CrudModelRef.formData; const data = tableRef.value.CrudModelRef.formData;
if (!originalData.value) originalData.value = data; if (!originalData.value) originalData.value = data;
if (!originalData.value) return;
const en = originalData.value.filter((d) => d.lang === 'en'); const en = originalData.value.filter((d) => d.lang === 'en');
for (const translation of en) { for (const translation of en) {
translation['secondLang'] = originalData.value.find( translation['secondLang'] = originalData.value.find(
(d) => d[pk.value] == translation[pk.value] && d['lang'] == lang.value (d) =>
)?.[value.value]; d[primaryKey.value] == translation[primaryKey.value] &&
d['lang'] == lang.value
)?.[field.value];
} }
console.log('data: ', en); console.log('data: ', en);
tableRef.value.CrudModelRef.formData = en; await tableRef.value.CrudModelRef.resetData(en);
} }
function resetOriginalData() { function resetOriginalData() {
originalData.value = null; originalData.value = null;
} }
function upsertI18n() {
axios.patch(url.value, {});
}
</script> </script>
<template> <template>
<FetchData url="Languages" @on-fetch="(data) => (langs = data)" auto-load /> <FetchData url="Languages" @on-fetch="(data) => (langs = data)" auto-load />
<VnSubToolbar /> <FetchData
<VnTable url="Applications/get-i18n-tables"
ref="tableRef" @on-fetch="(data) => (tables = data)"
data-key="translations"
url="CompanyI18ns"
:columns="columns"
:right-search="false"
:is-editable="true"
auto-load auto-load
@on-fetch="loadTable()" />
> <VnSubToolbar>
<template #top-left> <template #st-data>
<div class="row no-wrap q-gutter-x-sm">
<VnSelect <VnSelect
v-model="lang" :label="t('table')"
:options="langs" v-model="table"
option-label="code" :options="tables"
option-value="code" option-label="tableName"
option-value="tableName"
@update:model-value="resetOriginalData()" @update:model-value="resetOriginalData()"
:emit-value="false"
/> />
<VnSelect <VnSelect
:label="t('lang')" :label="t('lang')"
@ -94,11 +95,31 @@ function resetOriginalData() {
option-value="code" option-value="code"
@update:model-value="loadTable()" @update:model-value="loadTable()"
/> />
</div>
</template> </template>
</VnTable> </VnSubToolbar>
<VnTable
ref="tableRef"
data-key="translations"
:url="url"
:columns="columns"
:right-search="false"
:is-editable="true"
@on-fetch="loadTable()"
:save-fn="upsertI18n"
/>
</template> </template>
<i18n> <i18n>
es:
primaryKey: Clave primaria
defaultLang(en): Idioma por defecto(Eng)
secondLang: Idioma secundario
table: Tabla
lang: Idioma
en:
primaryKey: Primary key
defaultLang(en): Default language(Eng)
secondLang: Second language
table: Table
lang: Language
</i18n> </i18n>