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,
formData,
vnPaginateRef,
resetData,
});
onBeforeRouteLeave((to, from, next) => {

View File

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

View File

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

View File

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

View File

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

View File

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