Commit 042f7e41 authored by hucy's avatar hucy

feat:vue-i18n学习

parent 2b9b1213
import { boot } from 'quasar/wrappers'; import { boot } from 'quasar/wrappers';
import { createI18n } from 'vue-i18n'; import { createI18n } from 'vue-i18n';
import messages from 'src/i18n'; import globalLang from 'src/i18n';
export default boot(({ app }) => { export default boot(({ app }) => {
// Create I18n instance // Create I18n instance
...@@ -8,9 +8,10 @@ export default boot(({ app }) => { ...@@ -8,9 +8,10 @@ export default boot(({ app }) => {
// something vue-i18n options here ... // something vue-i18n options here ...
legacy: false, // you must set `false`, to use Composition API legacy: false, // you must set `false`, to use Composition API
locale: 'zh-CN', // set current locale locale: 'zh-CN', // set current locale
formatFallbackMessages: true,
// missingWarn: false, // missingWarn: false,
// fallbackWarn: false, // fallbackWarn: false,
messages, messages: globalLang,
}); });
// Tell app to use the I18n instance // Tell app to use the I18n instance
......
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
--> -->
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, computed, nextTick } from 'vue'; import { ref, reactive, computed, nextTick } from 'vue';
import { useI18n } from 'vue-i18n';
import { useMessage } from 'src/common/hooks'; import { useMessage } from 'src/common/hooks';
import { getObjectURL } from './utils'; import { getObjectURL } from './utils';
var XLSX = require('xlsx'); var XLSX = require('xlsx');
const { t } = useI18n();
const { warn } = useMessage(); const { warn } = useMessage();
interface IDetailProps { interface IDetailProps {
...@@ -210,7 +212,7 @@ function closeViewDialog() { ...@@ -210,7 +212,7 @@ function closeViewDialog() {
dense dense
size="12px" size="12px"
label="OK" label="OK"
title="确认上传" :title="t('Confirm upload')"
:style="{ :style="{
backgroundColor: props.dark ? props.bgColor : '#fff', backgroundColor: props.dark ? props.bgColor : '#fff',
color: props.dark ? darkLight : props.bgColor, color: props.dark ? darkLight : props.bgColor,
...@@ -223,7 +225,7 @@ function closeViewDialog() { ...@@ -223,7 +225,7 @@ function closeViewDialog() {
flat flat
icon="bi-trash" icon="bi-trash"
size="12px" size="12px"
title="清除所有" :title="t('clear all')"
:style="{ color: props.dark ? props.bgColor : '#fff' }" :style="{ color: props.dark ? props.bgColor : '#fff' }"
@click="removeAll" @click="removeAll"
/> />
...@@ -243,8 +245,8 @@ function closeViewDialog() { ...@@ -243,8 +245,8 @@ function closeViewDialog() {
push push
icon="add" icon="add"
size="12px" size="12px"
title="选择文件" :title="t('Select file')"
label="选择文件" :label="t('Select file')"
:style="{ :style="{
backgroundColor: props.dark ? props.bgColor : '#fff', backgroundColor: props.dark ? props.bgColor : '#fff',
color: props.dark ? darkLight : props.bgColor, color: props.dark ? darkLight : props.bgColor,
...@@ -276,7 +278,7 @@ function closeViewDialog() { ...@@ -276,7 +278,7 @@ function closeViewDialog() {
flat flat
dense dense
size="12px" size="12px"
title="预览" :title="t('preview')"
icon="bi-eye" icon="bi-eye"
:style="{ color: props.bgColor }" :style="{ color: props.bgColor }"
@click="onView(item)" @click="onView(item)"
...@@ -287,7 +289,7 @@ function closeViewDialog() { ...@@ -287,7 +289,7 @@ function closeViewDialog() {
flat flat
dense dense
size="12px" size="12px"
title="从列表移除" :title="t('remove from list')"
icon="bi-x-circle" icon="bi-x-circle"
:style="{ color: props.bgColor }" :style="{ color: props.bgColor }"
@click="removeItem(index)" @click="removeItem(index)"
......
...@@ -3,4 +3,5 @@ export const Langs = [ ...@@ -3,4 +3,5 @@ export const Langs = [
{ label: '繁體中文', value: 'zh-TW' }, { label: '繁體中文', value: 'zh-TW' },
{ label: 'English', value: 'en-US' }, { label: 'English', value: 'en-US' },
{ label: '日本', value: 'ja' }, { label: '日本', value: 'ja' },
{ label: '韩国', value: 'ko' },
]; ];
export default { export default {
hello: 'hello!', ok: 'ok',
'World Cup': 'World Cup', 'Select file': 'Select file',
preview: 'preview',
'Upload files': 'Upload files',
'No file selected': 'No file selected',
'Confirm upload': 'Confirm upload',
'clear all': 'clear all',
'remove from list': 'remove from list',
}; };
...@@ -2,10 +2,12 @@ import zhCN from './zh-CN'; ...@@ -2,10 +2,12 @@ import zhCN from './zh-CN';
import zhTW from './zh-TW'; import zhTW from './zh-TW';
import enUS from './en-US'; import enUS from './en-US';
import ja from './ja'; import ja from './ja';
import ko from './ko';
export default { export default {
'zh-CN': zhCN, 'zh-CN': zhCN,
'zh-TW': zhTW, 'zh-TW': zhTW,
'en-US': enUS, 'en-US': enUS,
ja: ja, ja: ja,
ko: ko,
}; };
export default { export default {
hello: 'こんにちは!', ok: 'ok',
'World Cup': 'ワールドカップ', 'Select file': 'ファイルを選択',
preview: 'プレビュー',
'Upload files': 'ファイルをアップロードする',
'No file selected': 'ファイルが選択されていません',
'Confirm upload': 'アップロードを確認',
'clear all': 'すべてクリア',
'remove from list': 'リストから削除する',
}; };
export default {
ok: 'ok',
'Select file': '파일 선택',
preview: '시사',
'Upload files': '파일 올리기',
'No file selected': '선택한 파일이 없습니다',
'Confirm upload': '업로드 확인',
'clear all': '모두 지우기',
'remove from list': '목록에서 제거하다',
};
export default { export default {
hello: '你好!', ok: 'ok',
'World Cup': '世界杯', 'Select file': '选择文件',
preview: '预览',
'Upload files': '上传文件',
'No file selected': '未选择任何文件',
'Confirm upload': '确认上传',
'clear all': '清除所有',
'remove from list': '从列表移除',
}; };
export default { export default {
hello: '你好!', ok: 'ok',
'World Cup': '世界盃', 'Select file': '選擇文件',
preview: '預覽',
'Upload files': '上傳文件',
'No file selected': '未選擇任何文件',
'Confirm upload': '確認上傳',
'clear all': '清除所有',
'remove from list': '從列表移除',
}; };
...@@ -12,9 +12,8 @@ import { read, utils, writeFile } from 'xlsx'; ...@@ -12,9 +12,8 @@ import { read, utils, writeFile } from 'xlsx';
// var XLSX = require('xlsx'); // var XLSX = require('xlsx');
import lang from '../../lang'; import lang from '../../lang';
console.log('lang >>>>', lang);
const { t } = useI18n({}); const { t } = useI18n({ messages: lang });
const { warn } = useMessage(); const { warn } = useMessage();
const excelTypeList = ['xlsx', 'xls']; const excelTypeList = ['xlsx', 'xls'];
...@@ -52,7 +51,10 @@ const columns: any[] = [ ...@@ -52,7 +51,10 @@ const columns: any[] = [
}, },
]; ];
const uploadXlsxMsg = ref('未选择任何文件'); console.log('lll', t('No file selected'));
const hasUploadXlsxMsg = ref(false);
const uploadXlsxMsg = ref(t('No file selected'));
const state = reactive({ const state = reactive({
rows: [ rows: [
...@@ -135,6 +137,7 @@ function uploadXlsx() { ...@@ -135,6 +137,7 @@ function uploadXlsx() {
if (excelTypeList.includes(fileType)) { if (excelTypeList.includes(fileType)) {
uploadXlsxMsg.value = `${file.name}&nbsp;&nbsp;${size}${unit}`; uploadXlsxMsg.value = `${file.name}&nbsp;&nbsp;${size}${unit}`;
hasUploadXlsxMsg.value = true;
const data = await file.arrayBuffer(); const data = await file.arrayBuffer();
const wb = read(data); const wb = read(data);
const ws = wb.Sheets[wb.SheetNames[0]]; const ws = wb.Sheets[wb.SheetNames[0]];
...@@ -211,31 +214,13 @@ function exportTableData() { ...@@ -211,31 +214,13 @@ function exportTableData() {
/> />
</div> </div>
<div>
<q-btn
:label="t('hello1')"
square
push
style="background: #4aacc5; color: white"
/>
</div>
<div>
<q-btn
:label="t('World Cup')"
square
push
style="background: #4aacc5; color: white"
/>
</div>
<div> <div>
<q-table :rows="state.rows" :columns="columns" row-key="name" /> <q-table :rows="state.rows" :columns="columns" row-key="name" />
</div> </div>
</div> </div>
<div class="upload-box"> <div class="upload-box">
<div style="width: 400px; height: 232px" class="q-my-md"> <div style="width: 400px; height: 232px" class="q-my-md">
<!-- FAD4D4 --> <com-up-loader bg-color="#FAD4D4" dark multiple @on-ok="uploadOk" />
<com-up-loader bg-color="#d9d9f3" dark multiple @on-ok="uploadOk" />
</div> </div>
<div style="width: 400px; height: 232px" class="q-my-md"> <div style="width: 400px; height: 232px" class="q-my-md">
<com-up-loader bg-color="#A4BE7B" multiple @on-ok="uploadOk" /> <com-up-loader bg-color="#A4BE7B" multiple @on-ok="uploadOk" />
...@@ -244,7 +229,7 @@ function exportTableData() { ...@@ -244,7 +229,7 @@ function exportTableData() {
<div class="upload-xlsx-box"> <div class="upload-xlsx-box">
<div> <div>
<q-btn <q-btn
label="上传文件" :label="t('Upload files')"
square square
push push
:icon="ICON.upload" :icon="ICON.upload"
...@@ -253,8 +238,9 @@ function exportTableData() { ...@@ -253,8 +238,9 @@ function exportTableData() {
/> />
</div> </div>
<div> <div>
<q-chip :ripple="false" square <q-chip :ripple="false" square>
><span v-html="uploadXlsxMsg"></span> <span v-if="!hasUploadXlsxMsg">{{ t('No file selected') }}</span>
<span v-else v-html="uploadXlsxMsg"></span>
</q-chip> </q-chip>
</div> </div>
</div> </div>
......
...@@ -2,10 +2,12 @@ import zhCN from './zh-CN'; ...@@ -2,10 +2,12 @@ import zhCN from './zh-CN';
import zhTW from './zh-TW'; import zhTW from './zh-TW';
import enUS from './en-US'; import enUS from './en-US';
import ja from './ja'; import ja from './ja';
import ko from './ko';
export default { export default {
'zh-CN': zhCN, 'zh-CN': zhCN,
'zh-TW': zhTW, 'zh-TW': zhTW,
'en-US': enUS, 'en-US': enUS,
ja: ja, ja: ja,
ko: ko,
}; };
export default {
hello: '안녕하십니까',
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment