From 9331434c1466ba8d6f19c1855dfd439fd40c1acc Mon Sep 17 00:00:00 2001 From: halfcoke Date: Sat, 25 Nov 2023 14:13:23 +0800 Subject: [PATCH] feat(i18n): yaml to json --- src/composable/validation.ts | 3 +-- src/tools/yaml-to-json-converter/locales/en.yml | 9 +++++++++ src/tools/yaml-to-json-converter/locales/zh.yml | 9 +++++++++ src/tools/yaml-to-json-converter/yaml-to-json.vue | 9 +++++---- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/tools/yaml-to-json-converter/locales/en.yml create mode 100644 src/tools/yaml-to-json-converter/locales/zh.yml diff --git a/src/composable/validation.ts b/src/composable/validation.ts index 472ca4b2..bae798c0 100644 --- a/src/composable/validation.ts +++ b/src/composable/validation.ts @@ -6,7 +6,7 @@ type ValidatorReturnType = unknown; export interface UseValidationRule { validator: (value: T) => ValidatorReturnType - message: string + message: any } export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean { @@ -56,7 +56,6 @@ export function useValidation({ watch( [source, ...watchRefs], () => { - state.message = ''; state.status = undefined; for (const rule of get(rules)) { diff --git a/src/tools/yaml-to-json-converter/locales/en.yml b/src/tools/yaml-to-json-converter/locales/en.yml new file mode 100644 index 00000000..7774ac88 --- /dev/null +++ b/src/tools/yaml-to-json-converter/locales/en.yml @@ -0,0 +1,9 @@ +tools: + yaml-to-json-converter: + title: 'YAML to JSON converter' + description: 'Simply convert YAML to JSON with this live online converter.' + invalid: 'Provided JSON is not valid.' + your-yaml: 'Your YAML' + json-from-yaml: 'JSON from your YAML' + placeholder: + your-yaml: 'Paste your YAML here...' diff --git a/src/tools/yaml-to-json-converter/locales/zh.yml b/src/tools/yaml-to-json-converter/locales/zh.yml new file mode 100644 index 00000000..0a4245a1 --- /dev/null +++ b/src/tools/yaml-to-json-converter/locales/zh.yml @@ -0,0 +1,9 @@ +tools: + yaml-to-json-converter: + title: 'YAML to JSON' + description: '使用这个在线转换工具,简单地将YAML转换为JSON' + invalid: '提供的YAML有问题' + your-yaml: '原始YAML' + json-from-yaml: '转换后的JSON' + placeholder: + your-yaml: '在这粘贴你的YAML...' diff --git a/src/tools/yaml-to-json-converter/yaml-to-json.vue b/src/tools/yaml-to-json-converter/yaml-to-json.vue index 39c9297f..27973f6e 100644 --- a/src/tools/yaml-to-json-converter/yaml-to-json.vue +++ b/src/tools/yaml-to-json-converter/yaml-to-json.vue @@ -4,6 +4,7 @@ import type { UseValidationRule } from '@/composable/validation'; import { isNotThrowing } from '@/utils/boolean'; import { withDefaultOnError } from '@/utils/defaults'; +const { t } = useI18n(); function transformer(value: string) { return withDefaultOnError(() => { const obj = parseYaml(value); @@ -14,16 +15,16 @@ function transformer(value: string) { const rules: UseValidationRule[] = [ { validator: (value: string) => isNotThrowing(() => parseYaml(value)), - message: 'Provided YAML is not valid.', + message: computed(() => t('tools.yaml-to-json-converter.invalid')), }, ];