feat(i18n): yaml to json

This commit is contained in:
halfcoke 2023-11-25 14:13:23 +08:00
parent 7a70dbbe0c
commit 9c5688027a
3 changed files with 23 additions and 4 deletions

View file

@ -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...'

View file

@ -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...'

View file

@ -4,6 +4,7 @@ import type { UseValidationRule } from '@/composable/validation';
import { isNotThrowing } from '@/utils/boolean'; import { isNotThrowing } from '@/utils/boolean';
import { withDefaultOnError } from '@/utils/defaults'; import { withDefaultOnError } from '@/utils/defaults';
const { t } = useI18n();
function transformer(value: string) { function transformer(value: string) {
return withDefaultOnError(() => { return withDefaultOnError(() => {
const obj = parseYaml(value); const obj = parseYaml(value);
@ -14,16 +15,16 @@ function transformer(value: string) {
const rules: UseValidationRule<string>[] = [ const rules: UseValidationRule<string>[] = [
{ {
validator: (value: string) => isNotThrowing(() => parseYaml(value)), validator: (value: string) => isNotThrowing(() => parseYaml(value)),
message: 'Provided YAML is not valid.', message: computed(()=>t('tools.yaml-to-json-converter.invalid')),
}, },
]; ];
</script> </script>
<template> <template>
<format-transformer <format-transformer
input-label="Your YAML" :input-label="t('tools.yaml-to-json-converter.your-yaml')"
input-placeholder="Paste your yaml here..." :input-placeholder="t('tools.yaml-to-json-converter.placeholder.your-yaml')"
output-label="JSON from your YAML" :output-label="t('tools.yaml-to-json-converter.json-from-yaml')"
output-language="json" output-language="json"
:input-validation-rules="rules" :input-validation-rules="rules"
:transformer="transformer" :transformer="transformer"