Skip to content

Commit 369770b

Browse files
committed
add translations
1 parent 4c4e84f commit 369770b

9 files changed

Lines changed: 367 additions & 75 deletions

File tree

packages/vue-vuetify/src/complex/MixedRenderer.vue

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
density="compact"
4949
hide-details
5050
clearable
51-
label="Search"
51+
:label="mixedTranslations.searchLabel"
5252
:prepend-inner-icon="icons.current.value.search"
5353
v-bind="vuetifyProps('v-text-field')"
5454
/>
@@ -113,14 +113,19 @@
113113
"
114114
variant="text"
115115
size="x-small"
116+
:aria-label="
117+
showPrimitivesInTree
118+
? mixedTranslations.hidePrimitives
119+
: mixedTranslations.showPrimitives
120+
"
116121
@click.stop="toggleShowPrimitives"
117122
/>
118123
</template>
119124
<span>
120125
{{
121126
showPrimitivesInTree
122-
? 'Hide primitives'
123-
: 'Show primitives'
127+
? mixedTranslations.hidePrimitives
128+
: mixedTranslations.showPrimitives
124129
}}
125130
</span>
126131
</v-tooltip>
@@ -131,26 +136,36 @@
131136
v-bind="props"
132137
class="mixed-tree-action mixed-hover-action"
133138
:icon="icons.current.value.itemEdit"
139+
:aria-label="
140+
mixedTranslations.renameAriaLabel(
141+
item.label,
142+
)
143+
"
134144
variant="text"
135145
size="x-small"
136146
@click.stop="startRename(item)"
137147
/>
138148
</template>
139-
<span>Rename</span>
149+
<span>{{ mixedTranslations.renameTooltip }}</span>
140150
</v-tooltip>
141151
<v-tooltip v-if="item.canDelete" location="top">
142152
<template #activator="{ props }">
143153
<v-btn
144154
v-bind="props"
145155
class="mixed-tree-action mixed-hover-action"
146156
:icon="icons.current.value.itemDelete"
157+
:aria-label="
158+
mixedTranslations.deleteAriaLabel(
159+
item.label,
160+
)
161+
"
147162
variant="text"
148163
size="x-small"
149164
color="error"
150165
@click.stop="deleteNode(item)"
151166
/>
152167
</template>
153-
<span>Delete</span>
168+
<span>{{ mixedTranslations.deleteTooltip }}</span>
154169
</v-tooltip>
155170
</template>
156171
</div>
@@ -209,13 +224,14 @@
209224
v-bind="props"
210225
class="mixed-navigate-button"
211226
:icon="icons.current.value.visibilityOn"
227+
:aria-label="mixedTranslations.viewAriaLabel(computedLabel)"
212228
variant="text"
213229
color="primary"
214230
:disabled="!navigationContext"
215231
@click="selectCurrentPath"
216232
/>
217233
</template>
218-
<span>View {{ computedLabel }}</span>
234+
<span>{{ mixedTranslations.viewTooltip(computedLabel) }}</span>
219235
</v-tooltip>
220236
</div>
221237
</template>
@@ -262,7 +278,10 @@
262278
<script lang="ts">
263279
import { AdditionalPropertiesTranslationEnum } from '@/i18n';
264280
import { additionalPropertiesDefaultTranslations } from '@/i18n/additionalPropertiesTranslations';
265-
import { getAdditionalPropertiesTranslations } from '@/i18n/i18nUtil';
281+
import {
282+
getAdditionalPropertyTranslation,
283+
getMixedRendererTranslations,
284+
} from '@/i18n/i18nUtil';
266285
import {
267286
Resolve,
268287
createControlElement,
@@ -285,6 +304,7 @@ import {
285304
useTranslator,
286305
type RendererProps,
287306
} from '@jsonforms/vue';
307+
import type { ErrorObject } from 'ajv';
288308
import cloneDeep from 'lodash/cloneDeep';
289309
import get from 'lodash/get';
290310
import isEqual from 'lodash/isEqual';
@@ -295,7 +315,6 @@ import {
295315
inject,
296316
provide,
297317
ref,
298-
unref,
299318
watch,
300319
type DefineComponent,
301320
type InjectionKey,
@@ -661,16 +680,17 @@ function prepareChildSchema(
661680
key: string,
662681
index: number | null,
663682
rootSchema: JsonSchema,
683+
itemLabel?: string,
664684
): JsonSchema {
665685
let childSchema: JsonSchema | undefined;
666686
667687
if (index !== null) {
668688
childSchema = getArrayItemSchema(currentSchema, index, rootSchema);
669689
childSchema = childSchema
670-
? { ...childSchema, title: `Item ${index}` }
690+
? { ...childSchema, title: itemLabel }
671691
: {
672692
type: [...JSON_TYPES],
673-
title: `Item ${index}`,
693+
title: itemLabel,
674694
};
675695
} else {
676696
childSchema = findPropertySchema(currentSchema, key, rootSchema);
@@ -767,6 +787,7 @@ function buildTreeFromData(
767787
enabled: boolean,
768788
readonly: boolean,
769789
showPrimitives: boolean,
790+
itemLabel: (index: number) => string,
770791
): MixedTreeNode[] {
771792
const dataType = getJsonDataType(data);
772793
if (dataType !== 'object' && dataType !== 'array') {
@@ -880,16 +901,17 @@ function buildTreeFromData(
880901
value.forEach((childValue: any, index: number) => {
881902
const childType = getJsonDataType(childValue);
882903
const childPath = composePropertyPath(currentPath, `${index}`);
904+
const childLabel = itemLabel(index);
883905
const childSchema = prepareChildSchema(
884906
childType ?? 'object',
885907
currentSchema,
886908
'',
887909
index,
888910
rootSchema,
911+
childLabel,
889912
);
890913
const resolvedChildType =
891914
childType ?? getSchemaDefaultType(childSchema);
892-
const childLabel = `Item ${index}`;
893915
if (resolvedChildType === 'object' || resolvedChildType === 'array') {
894916
traverse(
895917
childValue ?? (resolvedChildType === 'array' ? [] : {}),
@@ -999,13 +1021,37 @@ const controlRenderer = defineComponent({
9991021
input.control.value.uischema,
10001022
input.control.value.path + '.additionalProperties',
10011023
);
1002-
const renameTranslations = getAdditionalPropertiesTranslations(
1024+
const translateAdditionalProperty = (
1025+
key: AdditionalPropertiesTranslationEnum,
1026+
propertyName: string,
1027+
) =>
1028+
getAdditionalPropertyTranslation(
1029+
t.value,
1030+
additionalPropertiesDefaultTranslations,
1031+
i18nAdditionalPropertiesPrefix,
1032+
key,
1033+
propertyName,
1034+
);
1035+
const i18nMixedRendererPrefix = getI18nKeyPrefix(
1036+
input.control.value.schema,
1037+
input.control.value.uischema,
1038+
input.control.value.path + '.mixedRenderer',
1039+
);
1040+
const mixedTranslations = getMixedRendererTranslations(
10031041
t.value,
1004-
additionalPropertiesDefaultTranslations,
1005-
i18nAdditionalPropertiesPrefix,
1006-
input.control.value.label,
1007-
renameValue,
1042+
i18nMixedRendererPrefix,
10081043
);
1044+
const translatePropertyNameSchemaError = (error: ErrorObject) =>
1045+
jsonforms.i18n?.translateError?.(
1046+
error,
1047+
t.value,
1048+
input.control.value.uischema,
1049+
) ??
1050+
error.message ??
1051+
translateAdditionalProperty(
1052+
AdditionalPropertiesTranslationEnum.propertyNameInvalid,
1053+
renameValue.value,
1054+
);
10091055
10101056
const mixedRenderInfos = computed<
10111057
(SchemaRenderInfo & {
@@ -1091,6 +1137,7 @@ const controlRenderer = defineComponent({
10911137
input.control.value.enabled,
10921138
input.control.value.readonly,
10931139
showPrimitivesInTree.value,
1140+
mixedTranslations.itemLabel,
10941141
)
10951142
: [],
10961143
);
@@ -1292,18 +1339,15 @@ const controlRenderer = defineComponent({
12921339
ajv,
12931340
});
12941341
renameError.value = getDynamicPropertyNameErrorMessage(validationError, {
1295-
alreadyDefined:
1296-
unref(
1297-
renameTranslations[
1298-
AdditionalPropertiesTranslationEnum.propertyAlreadyDefined
1299-
],
1300-
) ?? `Property '${trimmed}' already defined`,
1301-
invalid:
1302-
unref(
1303-
renameTranslations[
1304-
AdditionalPropertiesTranslationEnum.propertyNameInvalid
1305-
],
1306-
) ?? `Property name '${trimmed}' is invalid`,
1342+
alreadyDefined: translateAdditionalProperty(
1343+
AdditionalPropertiesTranslationEnum.propertyAlreadyDefined,
1344+
trimmed,
1345+
),
1346+
invalid: translateAdditionalProperty(
1347+
AdditionalPropertiesTranslationEnum.propertyNameInvalid,
1348+
trimmed,
1349+
),
1350+
schema: translatePropertyNameSchemaError,
13071351
});
13081352
if (renameError.value) {
13091353
return;
@@ -1432,6 +1476,7 @@ const controlRenderer = defineComponent({
14321476
renamingNodeId,
14331477
renameValue,
14341478
renameError,
1479+
mixedTranslations,
14351480
navigationContext,
14361481
toggleShowPrimitives,
14371482
startRename,

0 commit comments

Comments
 (0)