docs(Field): update i18n usage

This commit is contained in:
chenjiahan 2020-12-13 14:56:13 +08:00
parent 3452ee2a41
commit 65e14cd84a
10 changed files with 208 additions and 168 deletions

View File

@ -11,11 +11,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
message: '留言', message: '留言',
autosize: '高度自适应', autosize: '高度自适应',
@ -26,11 +26,14 @@ export default {
autosize: 'Auto Resize', autosize: 'Auto Resize',
placeholder: 'Message', placeholder: 'Message',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const value = ref(''); const value = ref('');
return { value };
return { t, value };
}, },
}; };
</script> </script>

View File

@ -10,11 +10,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
label: '文本', label: '文本',
placeholder: '请输入文本', placeholder: '请输入文本',
@ -23,11 +23,13 @@ export default {
label: 'Label', label: 'Label',
placeholder: 'Text', placeholder: 'Text',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const value = ref(''); const value = ref('');
return { value }; return { t, value };
}, },
}; };
</script> </script>

View File

@ -32,11 +32,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
text: '文本', text: '文本',
digit: '整数', digit: '整数',
@ -61,9 +61,11 @@ export default {
phonePlaceholder: 'Phone', phonePlaceholder: 'Phone',
numberPlaceholder: 'Number', numberPlaceholder: 'Number',
}, },
}, };
data() { export default {
setup() {
const t = useTranslate(i18n);
const state = reactive({ const state = reactive({
text: '', text: '',
phone: '', phone: '',
@ -72,7 +74,10 @@ export default {
password: '', password: '',
}); });
return toRefs(state); return {
...toRefs(state),
t,
};
}, },
}; };
</script> </script>

View File

@ -5,9 +5,10 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
export default { import { useTranslate } from '@demo/use-translate';
i18n: {
const i18n = {
'zh-CN': { 'zh-CN': {
text: '文本', text: '文本',
disabled: '禁用输入框', disabled: '禁用输入框',
@ -19,6 +20,13 @@ export default {
inputReadonly: 'Input Readonly', inputReadonly: 'Input Readonly',
inputDisabled: 'Input Disabled', inputDisabled: 'Input Disabled',
}, },
};
export default {
setup() {
const t = useTranslate(i18n);
return { t };
}, },
}; };
</script> </script>

View File

@ -17,11 +17,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
phone: '手机号', phone: '手机号',
errorInfo: '错误提示', errorInfo: '错误提示',
@ -34,15 +34,20 @@ export default {
phoneError: 'Invalid phone', phoneError: 'Invalid phone',
phonePlaceholder: 'Phone', phonePlaceholder: 'Phone',
}, },
}, };
data() { export default {
setup() {
const t = useTranslate(i18n);
const state = reactive({ const state = reactive({
phone: '123', phone: '123',
username: '', username: '',
}); });
return toRefs(state); return {
...toRefs(state),
t,
};
}, },
}; };
</script> </script>

View File

@ -16,11 +16,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
text: '文本', text: '文本',
formatValue: '格式化输入内容', formatValue: '格式化输入内容',
@ -33,17 +33,20 @@ export default {
formatOnBlur: 'Format On Blur', formatOnBlur: 'Format On Blur',
formatOnChange: 'Format On Change', formatOnChange: 'Format On Change',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const state = reactive({ const state = reactive({
value1: '', value1: '',
value2: '', value2: '',
}); });
const formatter = (value) => value.replace(/\d/g, ''); const formatter = (value: string) => value.replace(/\d/g, '');
return { return {
...toRefs(state), ...toRefs(state),
t,
formatter, formatter,
}; };
}, },

View File

@ -9,11 +9,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
text: '文本', text: '文本',
inputAlign: '输入框内容对齐', inputAlign: '输入框内容对齐',
@ -24,11 +24,14 @@ export default {
inputAlign: 'Input Align', inputAlign: 'Input Align',
alignPlaceHolder: 'Input Align Right', alignPlaceHolder: 'Input Align Right',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const value = ref(''); const value = ref('');
return { value };
return { t, value };
}, },
}; };
</script> </script>

View File

@ -16,11 +16,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
sms: '短信验证码', sms: '短信验证码',
sendSMS: '发送验证码', sendSMS: '发送验证码',
@ -33,11 +33,14 @@ export default {
insertButton: 'Insert Button', insertButton: 'Insert Button',
smsPlaceholder: 'SMS', smsPlaceholder: 'SMS',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const sms = ref(''); const sms = ref('');
return { sms };
return { t, sms };
}, },
}; };
</script> </script>

View File

@ -17,11 +17,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
text: '文本', text: '文本',
showIcon: '显示图标', showIcon: '显示图标',
@ -32,15 +32,20 @@ export default {
showIcon: 'Show Icon', showIcon: 'Show Icon',
showClearIcon: 'Show Clear Icon', showClearIcon: 'Show Clear Icon',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const state = reactive({ const state = reactive({
icon1: '', icon1: '',
icon2: '123', icon2: '123',
}); });
return toRefs(state); return {
...toRefs(state),
t,
};
}, },
}; };
</script> </script>

View File

@ -13,11 +13,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate';
export default { const i18n = {
i18n: {
'zh-CN': { 'zh-CN': {
message: '留言', message: '留言',
placeholder: '请输入留言', placeholder: '请输入留言',
@ -28,11 +28,14 @@ export default {
placeholder: 'Message', placeholder: 'Message',
showWordLimit: 'Show Word Limit', showWordLimit: 'Show Word Limit',
}, },
}, };
export default {
setup() { setup() {
const t = useTranslate(i18n);
const value = ref(''); const value = ref('');
return { value };
return { t, value };
}, },
}; };
</script> </script>