Skip to content

Commit

Permalink
Readd i18n translator to vue example app
Browse files Browse the repository at this point in the history
  • Loading branch information
sdirix committed Jul 15, 2022
1 parent c41c9e9 commit 6ab3a27
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/vue/vue-vanilla/dev/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { JsonFormsI18nState } from '@jsonforms/core';
import { ErrorObject } from 'ajv';
import { getExamples } from '../../../../examples';
import get from 'lodash/get';
// mergeStyles combines all classes from both styles definitions into one
const myStyles = mergeStyles(defaultStyles, {
Expand All @@ -24,6 +25,7 @@ export default defineComponent({
const i18n: Partial<JsonFormsI18nState> = { locale: 'en' };
const additionalErrors: ErrorObject[] = [];
return {
data: {},
renderers: Object.freeze(vanillaRenderers),
currentExampleName: examples[0].name,
examples,
Expand All @@ -43,10 +45,22 @@ export default defineComponent({
methods: {
onChange(event: JsonFormsChangeEvent) {
console.log(event);
this.data = event.data;
},
onExampleChange(event: any) {
this.currentExampleName = event.target.value;
}
},
translationChange(event: any) {
try {
const input = JSON.parse(event.target.value);
(this as any).i18n.translate = (key: string, defaultMessage: string | undefined) => {
const translated = get(input, key) as string;
return translated ?? defaultMessage;
};
} catch (error) {
console.log('invalid translation input');
}
},
},
provide() {
return {
Expand Down Expand Up @@ -82,6 +96,13 @@ export default defineComponent({
>{{ option.label }}</option
>
</select>
<div class="data">
<h5>data</h5>
<pre>{{ JSON.stringify(data, null, 2) }}
</pre>
<h5>i18n translator</h5>
<textarea @change="translationChange"></textarea>
</div>
</div>

<div class="form">
Expand All @@ -93,8 +114,8 @@ export default defineComponent({
:config="config"
:i18n="i18n"
:additional-errors="additionalErrors"
@change="onChange"
/>
@change="onChange">
</json-forms>
</div>
</div>
</template>

0 comments on commit 6ab3a27

Please sign in to comment.