WIP(translate): translate converter category all tools

This commit is contained in:
Amery2010 2023-12-26 23:57:28 +08:00
parent 2ee3b01105
commit 2da11a7242
68 changed files with 716 additions and 174 deletions

View file

@ -1,10 +1,11 @@
import { Binary } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: 'Text to ASCII binary',
name: translate('tools.text-to-binary.title'),
path: '/text-to-binary',
description: 'Convert text to its ASCII binary representation and vice versa.',
description: translate('tools.text-to-binary.description'),
keywords: ['text', 'to', 'binary', 'converter', 'encode', 'decode', 'ascii'],
component: () => import('./text-to-binary.vue'),
icon: Binary,

View file

@ -0,0 +1,22 @@
tools:
text-to-binary:
title: Text to ASCII binary
description: Convert text to its ASCII binary representation and vice versa.
textToBinary:
title: Text to ASCII binary
inputLabel: Enter text to convert to binary
inputPlaceholder: e.g. "Hello world"
outputLabel: Binary from your text
outputPlaceholder: The binary representation of your text will be here
copyBinary: Copy binary to clipboard
binaryToText:
title: ASCII binary to text
inputLabel: Enter binary to convert to text
inputPlaceholder: e.g. "01001000 01100101 01101100 01101100 01101111"
outputLabel: Text from your binary
outputPlaceholder: The text representation of your binary will be here
copyText: Copy text to clipboard
invalidMessage: Binary should be a valid ASCII binary string with multiples of 8 bits
invalidBinaryString: Invalid binary string

View file

@ -0,0 +1,22 @@
tools:
text-to-binary:
title: 文本转 ASCII 二进制
description: 将文本转换为其 ASCII 二进制表示,反之亦然。
textToBinary:
title: 文本转 ASCII 二进制
inputLabel: 输入要转换为二进制的文本
inputPlaceholder: 例如 "Hello world"
outputLabel: 您的文本的二进制
outputPlaceholder: 您的文本的二进制表示将显示在这里
copyBinary: 复制二进制到剪贴板
binaryToText:
title: ASCII 二进制转文本
inputLabel: 输入要转换为文本的二进制
inputPlaceholder: 例如 "01001000 01100101 01101100 01101100 01101111"
outputLabel: 您的二进制的文本
outputPlaceholder: 您的二进制的文本表示将显示在这里
copyText: 复制文本到剪贴板
invalidMessage: 二进制应为有效的 ASCII 二进制字符串,且位数为 8 的倍数
invalidBinaryString: 无效的二进制字符串

View file

@ -1,3 +1,5 @@
import { translate } from '@/plugins/i18n.plugin';
export { convertTextToAsciiBinary, convertAsciiBinaryToText };
function convertTextToAsciiBinary(text: string, { separator = ' ' }: { separator?: string } = {}): string {
@ -11,7 +13,7 @@ function convertAsciiBinaryToText(binary: string): string {
const cleanBinary = binary.replace(/[^01]/g, '');
if (cleanBinary.length % 8) {
throw new Error('Invalid binary string');
throw new Error(translate('tools.text-to-binary.invalidBinaryString'));
}
return cleanBinary

View file

@ -4,6 +4,8 @@ import { withDefaultOnError } from '@/utils/defaults';
import { useCopy } from '@/composable/copy';
import { isNotThrowing } from '@/utils/boolean';
const { t } = useI18n();
const inputText = ref('');
const binaryFromText = computed(() => convertTextToAsciiBinary(inputText.value));
const { copy: copyBinary } = useCopy({ source: binaryFromText });
@ -13,29 +15,29 @@ const textFromBinary = computed(() => withDefaultOnError(() => convertAsciiBinar
const inputBinaryValidationRules = [
{
validator: (value: string) => isNotThrowing(() => convertAsciiBinaryToText(value)),
message: 'Binary should be a valid ASCII binary string with multiples of 8 bits',
message: t('tools.text-to-binary.invalidMessage'),
},
];
const { copy: copyText } = useCopy({ source: textFromBinary });
</script>
<template>
<c-card title="Text to ASCII binary">
<c-input-text v-model:value="inputText" multiline placeholder="e.g. 'Hello world'" label="Enter text to convert to binary" autosize autofocus raw-text test-id="text-to-binary-input" />
<c-input-text v-model:value="binaryFromText" label="Binary from your text" multiline raw-text readonly mt-2 placeholder="The binary representation of your text will be here" test-id="text-to-binary-output" />
<c-card :title="t('tools.text-to-binary.textToBinary.title')">
<c-input-text v-model:value="inputText" multiline :placeholder="t('tools.text-to-binary.textToBinary.inputPlaceholder')" label="t('tools.text-to-binary.textToBinary.inputLabel')" autosize autofocus raw-text test-id="text-to-binary-input" />
<c-input-text v-model:value="binaryFromText" :label="t('tools.text-to-binary.textToBinary.outputLabel')" multiline raw-text readonly mt-2 :placeholder="t('tools.text-to-binary.textToBinary.outputPlaceholder')" test-id="text-to-binary-output" />
<div mt-2 flex justify-center>
<c-button :disabled="!binaryFromText" @click="copyBinary()">
Copy binary to clipboard
{{ t('tools.text-to-binary.textToBinary.copyBinary') }}
</c-button>
</div>
</c-card>
<c-card title="ASCII binary to text">
<c-input-text v-model:value="inputBinary" multiline placeholder="e.g. '01001000 01100101 01101100 01101100 01101111'" label="Enter binary to convert to text" autosize raw-text :validation-rules="inputBinaryValidationRules" test-id="binary-to-text-input" />
<c-input-text v-model:value="textFromBinary" label="Text from your binary" multiline raw-text readonly mt-2 placeholder="The text representation of your binary will be here" test-id="binary-to-text-output" />
<c-card :title="t('tools.text-to-binary.binaryToText.title')">
<c-input-text v-model:value="inputBinary" multiline :placeholder="t('tools.text-to-binary.binaryToText.inputPlaceholder')" :label="t('tools.text-to-binary.binaryToText.inputLabel')" autosize raw-text :validation-rules="inputBinaryValidationRules" test-id="binary-to-text-input" />
<c-input-text v-model:value="textFromBinary" :label="t('tools.text-to-binary.binaryToText.outputLabel')" multiline raw-text readonly mt-2 :placeholder="t('tools.text-to-binary.binaryToText.outputPlaceholder')" test-id="binary-to-text-output" />
<div mt-2 flex justify-center>
<c-button :disabled="!textFromBinary" @click="copyText()">
Copy text to clipboard
{{ t('tools.text-to-binary.binaryToText.copyText') }}
</c-button>
</div>
</c-card>