mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Translate system fields when creating new collections (#8104)
* translate system fields when create collections * handle '$t:' translations only on interface Co-authored-by: Jose Varela <joselcvarela@gmail.com>
This commit is contained in:
9
app/src/utils/translate-literal.ts
Normal file
9
app/src/utils/translate-literal.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { i18n } from '@/lang';
|
||||
|
||||
export function translate(literal: string): string {
|
||||
let translated = literal;
|
||||
|
||||
if (literal.startsWith('$t:')) translated = i18n.global.t(literal.replace('$t:', ''));
|
||||
|
||||
return translated;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { i18n } from '@/lang';
|
||||
import { translate as translateString } from './translate-literal';
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
export function translate<T extends Record<string, any>>(obj: T): T {
|
||||
@@ -6,8 +6,7 @@ export function translate<T extends Record<string, any>>(obj: T): T {
|
||||
|
||||
Object.entries(newObj).forEach(([key, val]) => {
|
||||
if (val && typeof val === 'object') (newObj as Record<string, any>)[key] = translate(val);
|
||||
if (val && typeof val === 'string' && val.startsWith('$t:'))
|
||||
(newObj as Record<string, any>)[key] = i18n.global.t(val.replace('$t:', ''));
|
||||
if (val && typeof val === 'string') (newObj as Record<string, any>)[key] = translateString(val);
|
||||
});
|
||||
|
||||
return newObj;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
:collection="part.collection"
|
||||
:field="part.field"
|
||||
/>
|
||||
<span v-else>{{ part }}</span>
|
||||
<span v-else>{{ translate(part) }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -27,6 +27,7 @@ import { DisplayConfig, Field } from '@directus/shared/types';
|
||||
import { getDisplays } from '@/displays';
|
||||
import ValueNull from '@/views/private/components/value-null';
|
||||
import { getDefaultDisplayForType } from '@/utils/get-default-display-for-type';
|
||||
import { translate } from '@/utils/translate-literal';
|
||||
|
||||
export default defineComponent({
|
||||
components: { ValueNull },
|
||||
@@ -113,7 +114,7 @@ export default defineComponent({
|
||||
.map((p) => p ?? null)
|
||||
);
|
||||
|
||||
return { parts, templateEl };
|
||||
return { parts, templateEl, translate };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user