From 7aee7aa1c3e65cc5ce250248065725a059b0019a Mon Sep 17 00:00:00 2001 From: halfcoke Date: Sat, 25 Nov 2023 14:58:18 +0800 Subject: [PATCH] feat(i18n): yaml to toml & json to yaml --- src/composable/validation.ts | 3 +-- src/tools/json-to-yaml-converter/json-to-yaml.vue | 9 +++++---- src/tools/json-to-yaml-converter/locales/en.yml | 9 +++++++++ src/tools/json-to-yaml-converter/locales/zh.yml | 9 +++++++++ src/tools/yaml-to-toml/locales/en.yml | 9 +++++++++ src/tools/yaml-to-toml/locales/zh.yml | 9 +++++++++ src/tools/yaml-to-toml/yaml-to-toml.vue | 11 ++++++----- 7 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 src/tools/json-to-yaml-converter/locales/en.yml create mode 100644 src/tools/json-to-yaml-converter/locales/zh.yml create mode 100644 src/tools/yaml-to-toml/locales/en.yml create mode 100644 src/tools/yaml-to-toml/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/json-to-yaml-converter/json-to-yaml.vue b/src/tools/json-to-yaml-converter/json-to-yaml.vue index cbaeb22d..f7dfe33b 100644 --- a/src/tools/json-to-yaml-converter/json-to-yaml.vue +++ b/src/tools/json-to-yaml-converter/json-to-yaml.vue @@ -5,21 +5,22 @@ import type { UseValidationRule } from '@/composable/validation'; import { isNotThrowing } from '@/utils/boolean'; import { withDefaultOnError } from '@/utils/defaults'; +const { t } = useI18n(); const transformer = (value: string) => withDefaultOnError(() => stringify(JSON5.parse(value)), ''); const rules: UseValidationRule[] = [ { validator: (value: string) => value === '' || isNotThrowing(() => stringify(JSON5.parse(value))), - message: 'Provided JSON is not valid.', + message: computed(() => t('tools.json-to-yaml-converter.invalid')), }, ];