多语言方案已优化,成功解决 APP 端 Method too large 的问题,cool-ui 语言包现已独立分离
This commit is contained in:
@@ -1,81 +1,32 @@
|
||||
<template>
|
||||
<cl-popup
|
||||
v-model="visible"
|
||||
direction="center"
|
||||
<cl-select
|
||||
ref="selectRef"
|
||||
v-model="active"
|
||||
:options="options"
|
||||
:show-trigger="false"
|
||||
:title="t('切换语言')"
|
||||
:pt="{
|
||||
className: '!rounded-3xl'
|
||||
}"
|
||||
>
|
||||
<view class="locale-set w-[500rpx] p-4 pt-0">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.value"
|
||||
class="p-2 px-3 my-1 rounded-xl flex flex-row items-center border border-solid border-surface-200"
|
||||
:class="{
|
||||
'!border-surface-600': isDark,
|
||||
'!bg-primary-500 !border-primary-500': active == item.value
|
||||
}"
|
||||
@tap="change(item.value)"
|
||||
>
|
||||
<cl-text
|
||||
:pt="{
|
||||
className: parseClass([
|
||||
'flex-1',
|
||||
[isDark || active == item.value, '!text-white', '!text-surface-700']
|
||||
])
|
||||
}"
|
||||
>{{ item.label }}</cl-text
|
||||
>
|
||||
|
||||
<cl-icon
|
||||
name="checkbox-circle-line"
|
||||
color="white"
|
||||
v-if="active == item.value"
|
||||
></cl-icon>
|
||||
</view>
|
||||
|
||||
<view class="flex flex-row mt-4">
|
||||
<cl-button
|
||||
size="large"
|
||||
text
|
||||
border
|
||||
type="light"
|
||||
:pt="{
|
||||
className: 'flex-1 !rounded-full h-[80rpx]'
|
||||
}"
|
||||
@tap="close"
|
||||
>{{ t("取消") }}</cl-button
|
||||
>
|
||||
<cl-button
|
||||
size="large"
|
||||
:pt="{
|
||||
className: 'flex-1 !rounded-full h-[80rpx]'
|
||||
}"
|
||||
@tap="confirm"
|
||||
>{{ t("确定") }}</cl-button
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
</cl-popup>
|
||||
:cancel-text="t('取消')"
|
||||
:confirm-text="t('确定')"
|
||||
></cl-select>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { isDark, parseClass } from "@/cool";
|
||||
import { locale, t, setLocale } from "@/locale";
|
||||
import { locale, setLocale, t } from "@/locale";
|
||||
import { useUi, type ClSelectOption } from "@/uni_modules/cool-ui";
|
||||
import { ref } from "vue";
|
||||
|
||||
type Item = {
|
||||
label: string;
|
||||
value: string;
|
||||
};
|
||||
const ui = useUi();
|
||||
|
||||
// 语言列表
|
||||
const list = [
|
||||
const options = [
|
||||
{
|
||||
label: "简体中文",
|
||||
value: "zh-cn"
|
||||
},
|
||||
{
|
||||
label: "繁体中文",
|
||||
value: "zh-tw"
|
||||
},
|
||||
{
|
||||
label: "English",
|
||||
value: "en"
|
||||
@@ -83,43 +34,50 @@ const list = [
|
||||
{
|
||||
label: "Español",
|
||||
value: "es"
|
||||
},
|
||||
{
|
||||
label: "日本語",
|
||||
value: "ja"
|
||||
},
|
||||
{
|
||||
label: "한국어",
|
||||
value: "ko"
|
||||
},
|
||||
{
|
||||
label: "Français",
|
||||
value: "fr"
|
||||
}
|
||||
] as Item[];
|
||||
] as ClSelectOption[];
|
||||
|
||||
const selectRef = ref<ClSelectComponentPublicInstance | null>(null);
|
||||
|
||||
// 当前语言
|
||||
const active = ref(locale.value);
|
||||
|
||||
// 是否可见
|
||||
const visible = ref(false);
|
||||
|
||||
// 打开
|
||||
function open() {
|
||||
visible.value = true;
|
||||
active.value = locale.value;
|
||||
|
||||
if (["zh-Hans", "zh"].some((e) => e == locale.value)) {
|
||||
active.value = "zh-cn";
|
||||
}
|
||||
|
||||
selectRef.value!.open((value) => {
|
||||
ui.showLoading("切换中");
|
||||
|
||||
setTimeout(() => {
|
||||
setLocale(value as string);
|
||||
ui.hideLoading();
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭
|
||||
function close() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 切换语言
|
||||
function change(value: string) {
|
||||
active.value = value;
|
||||
}
|
||||
|
||||
// 确定
|
||||
function confirm() {
|
||||
setLocale(active.value);
|
||||
close();
|
||||
selectRef.value!.close();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
visible,
|
||||
open,
|
||||
close
|
||||
});
|
||||
|
||||
2178
locale/en.json
Normal file
2178
locale/en.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
2178
locale/es.json
Normal file
2178
locale/es.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
2178
locale/fr.json
Normal file
2178
locale/fr.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,31 @@
|
||||
import { isNull, forInObject, isEmpty, storage, router } from "@/cool";
|
||||
import { ref } from "vue";
|
||||
import { zhcn } from "./zh-cn";
|
||||
import { en } from "./en";
|
||||
import { es } from "./es";
|
||||
import zhcn from "./zh-cn.json";
|
||||
import zhtw from "./zh-tw.json";
|
||||
import en from "./en.json";
|
||||
import es from "./es.json";
|
||||
import ja from "./ja.json";
|
||||
import ko from "./ko.json";
|
||||
import fr from "./fr.json";
|
||||
import { config } from "@/config";
|
||||
|
||||
// 语言包对象,包含所有支持的语言
|
||||
// 解析语言包
|
||||
function parse(val: string[][]) {
|
||||
return val[0][0].split("<__&__>").map((e) => e.split("<__=__>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 语言包映射对象,包含所有已支持的语言。
|
||||
* 如需新增语言,只需新建对应的 xx.json 文件并在此处引入即可。
|
||||
*/
|
||||
const messages = {
|
||||
"zh-cn": zhcn,
|
||||
en,
|
||||
es
|
||||
"zh-cn": parse(zhcn),
|
||||
"zh-tw": parse(zhtw),
|
||||
en: parse(en),
|
||||
es: parse(es),
|
||||
ja: parse(ja),
|
||||
ko: parse(ko),
|
||||
fr: parse(fr)
|
||||
};
|
||||
|
||||
// 当前语言,默认中文
|
||||
|
||||
2178
locale/ja.json
Normal file
2178
locale/ja.json
Normal file
File diff suppressed because it is too large
Load Diff
2178
locale/ko.json
Normal file
2178
locale/ko.json
Normal file
File diff suppressed because it is too large
Load Diff
2178
locale/zh-cn.json
Normal file
2178
locale/zh-cn.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
2178
locale/zh-tw.json
Normal file
2178
locale/zh-tw.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,2 +1,3 @@
|
||||
import "./locale";
|
||||
export * from "./types";
|
||||
export * from "./hooks";
|
||||
|
||||
1
uni_modules/cool-ui/locale/en.json
Normal file
1
uni_modules/cool-ui/locale/en.json
Normal file
@@ -0,0 +1 @@
|
||||
[["最少需要{min}个字符","At least {min} characters are required"],["最大值为{max}","The maximum value is {max}"],["最多允许{max}个字符","A maximum of {max} characters are allowed"],["格式不正确","The format is incorrect"],["验证失败","Verification failed"],["暂无数据","No data available"],["加载中","Loading"],["上传 / 拍摄","Upload / Shoot"],["请输入","Please enter"],["请选择","Please select"],["小时","Hour"],["分钟","Minute"],["秒数","Seconds"],["确定","OK"],["取消","Cancel"],["年","Year"],["月","Month"],["日","Day"],["时","Hour"],["分","Minute"],["秒","Second"],["开始日期","Start date"],["结束日期","End date"],["至","To"],["今天","Today"],["近7天","Last 7 days"],["近30天","Last 30 days"],["近90天","Last 90 days"],["近一年","Last year"],["请选择完整时间范围","Please select a complete time range"],["开始日期不能大于结束日期","The start date cannot be greater than the end date"],["提示","Tip"],["没有更多了","There are no more"],["下拉刷新","Pull down to refresh"],["释放立即刷新","Release to immediately refresh"],["密码键盘","Password keyboard"],["安全键盘,请放心输入","Secure keyboard, please enter with confidence"],["请输入内容","Please enter content"],["请输入{minlength}到{maxlength}位密码","Please enter a password of {minlength} to {maxlength} digits"],["最多输入{maxlength}位","Maximum input of {maxlength} digits"],["数字键盘","Numeric keyboard"],["身份证号码格式不正确","The ID number format is incorrect"],["车牌键盘","License plate keyboard"],["车牌号格式不正确","The license plate number format is incorrect"],["此字段为必填项","This field is required"],["最小值为{min}","The minimum value is {min}"]]
|
||||
1
uni_modules/cool-ui/locale/es.json
Normal file
1
uni_modules/cool-ui/locale/es.json
Normal file
@@ -0,0 +1 @@
|
||||
[["最少需要{min}个字符","Se necesitan como mínimo {min} caracteres"],["最大值为{max}","El valor máximo es {max}"],["最多允许{max}个字符","Se permiten como máximo {max} caracteres"],["格式不正确","Formato incorrecto"],["验证失败","Validación fallida"],["暂无数据","No hay datos disponibles"],["加载中","Cargando"],["上传 / 拍摄","Subir / Tomar"],["请输入","Por favor, ingrese"],["请选择","Por favor, seleccione"],["小时","horas"],["分钟","minutos"],["秒数","segundos"],["确定","Aceptar"],["取消","Cancelar"],["年","años"],["月","meses"],["日","días"],["时","horas"],["分","minutos"],["秒","segundos"],["开始日期","Fecha de inicio"],["结束日期","Fecha de fin"],["至","hasta"],["今天","Hoy"],["近7天","Últimos 7 días"],["近30天","Últimos 30 días"],["近90天","Últimos 90 días"],["近一年","Último año"],["请选择完整时间范围","Seleccione un rango de tiempo completo"],["开始日期不能大于结束日期","La fecha de inicio no puede ser mayor que la fecha de finalización"],["提示","Sugerencia"],["没有更多了","No hay más"],["下拉刷新","Refrescar al deslizar hacia abajo"],["释放立即刷新","Liberar para actualizar inmediatamente"],["密码键盘","Teclado de contraseña"],["安全键盘,请放心输入","Teclado seguro, ingrese con confianza"],["请输入内容","Ingrese el contenido"],["请输入{minlength}到{maxlength}位密码","Ingrese una contraseña de {minlength} a {maxlength} dígitos"],["最多输入{maxlength}位","Máximo {maxlength} dígitos"],["数字键盘","Teclado numérico"],["身份证号码格式不正确","El formato del número de identificación personal es incorrecto"],["车牌键盘","Teclado de matrícula"],["车牌号格式不正确","El formato de la matrícula es incorrecto"],["此字段为必填项","Este campo es obligatorio"],["最小值为{min}","El valor mínimo es {min}"]]
|
||||
1
uni_modules/cool-ui/locale/fr.json
Normal file
1
uni_modules/cool-ui/locale/fr.json
Normal file
@@ -0,0 +1 @@
|
||||
[["最少需要{min}个字符","Il faut au moins {min} caractères"],["最大值为{max}","La valeur maximale est {max}"],["最多允许{max}个字符","Au plus {max} caractères sont autorisés"],["格式不正确","Format incorrect"],["验证失败","Vérification échouée"],["暂无数据","Aucune donnée pour le moment"],["加载中","Chargement en cours"],["上传 / 拍摄","Télécharger / Prendre une photo"],["请输入","Veuillez entrer"],["请选择","Veuillez sélectionner"],["小时","Heures"],["分钟","Minutes"],["秒数","Secondes"],["确定","OK"],["取消","Annuler"],["年","Ans"],["月","Mois"],["日","Jours"],["时","Heures"],["分","Minutes"],["秒","Secondes"],["开始日期","Date de début"],["结束日期","Date de fin"],["至","À"],["今天","Aujourd'hui"],["近7天","Derniers 7 jours"],["近30天","Dans les 30 derniers jours"],["近90天","Dans les 90 derniers jours"],["近一年","Dans l'année dernière"],["请选择完整时间范围","Veuillez sélectionner une plage de temps complète"],["开始日期不能大于结束日期","La date de début ne peut pas être supérieure à la date de fin"],["提示","Avertissement"],["没有更多了","Plus rien"],["下拉刷新","Actualiser en basculant"],["释放立即刷新","Actualiser immédiatement en libérant"],["密码键盘","Clavier de mot de passe"],["安全键盘,请放心输入","Clavier sécurisé, veuillez entrer en toute confiance"],["请输入内容","Veuillez entrer le contenu"],["请输入{minlength}到{maxlength}位密码","Veuillez entrer un mot de passe de {minlength} à {maxlength} caractères"],["最多输入{maxlength}位","Maximum {maxlength} caractères"],["数字键盘","Clavier numérique"],["身份证号码格式不正确","Le format de numéro d'identité est incorrect"],["车牌键盘","Clavier de plaque d'immatriculation"],["车牌号格式不正确","Le format de la plaque d'immatriculation est incorrect"],["此字段为必填项","Ce champ est obligatoire"],["最小值为{min}","La valeur minimale est de {min}"]]
|
||||
19
uni_modules/cool-ui/locale/index.ts
Normal file
19
uni_modules/cool-ui/locale/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { appendLocale } from "@/locale";
|
||||
|
||||
import zhcn from "./zh-cn.json";
|
||||
import en from "./en.json";
|
||||
import zhtw from "./zh-tw.json";
|
||||
import es from "./es.json";
|
||||
import ja from "./ja.json";
|
||||
import fr from "./fr.json";
|
||||
import ko from "./ko.json";
|
||||
|
||||
setTimeout(() => {
|
||||
appendLocale("zh-cn", zhcn);
|
||||
appendLocale("en", en);
|
||||
appendLocale("zh-tw", zhtw);
|
||||
appendLocale("es", es);
|
||||
appendLocale("ja", ja);
|
||||
appendLocale("fr", fr);
|
||||
appendLocale("ko", ko);
|
||||
}, 0);
|
||||
1
uni_modules/cool-ui/locale/ja.json
Normal file
1
uni_modules/cool-ui/locale/ja.json
Normal file
@@ -0,0 +1 @@
|
||||
[["最少需要{min}个字符","少なくとも{min}文字必要です"],["最大值为{max}","最大値は{max}です"],["最多允许{max}个字符","最大で{max}文字まで許可されます"],["格式不正确","形式が正しくありません"],["验证失败","検証に失敗しました"],["暂无数据","データはありません"],["加载中","読み込み中"],["上传 / 拍摄","アップロード / 撮影"],["请输入","入力してください"],["请选择","選択してください"],["小时","時間"],["分钟","分"],["秒数","秒数"],["确定","確定"],["取消","キャンセル"],["年","年"],["月","月"],["日","日"],["时","時"],["分","分"],["秒","秒"],["开始日期","開始日付"],["结束日期","終了日付"],["至","から"],["今天","今日"],["近7天","直近7日間"],["近30天","この30日間"],["近90天","この90日間"],["近一年","この1年間"],["请选择完整时间范围","完全な期間を選択してください"],["开始日期不能大于结束日期","開始日は終了日より大きくてはいけません"],["提示","ヒント"],["没有更多了","もうありません"],["下拉刷新","ドロップダウンで更新"],["释放立即刷新","すぐに解放して更新"],["密码键盘","パスワードキーボード"],["安全键盘,请放心输入","セキュリティキーボード、安心して入力してください"],["请输入内容","内容を入力してください"],["请输入{minlength}到{maxlength}位密码","{minlength}から{maxlength}桁のパスワードを入力してください"],["最多输入{maxlength}位","最大で{maxlength}桁まで入力可能"],["数字键盘","数字キーボード"],["身份证号码格式不正确","身分証番号の形式が正しくありません"],["车牌键盘","自動車番号キーボード"],["车牌号格式不正确","自動車番号の形式が正しくありません"],["此字段为必填项","このフィールドは必須項目です"],["最小值为{min}","最小値は{min}です"]]
|
||||
1
uni_modules/cool-ui/locale/ko.json
Normal file
1
uni_modules/cool-ui/locale/ko.json
Normal file
@@ -0,0 +1 @@
|
||||
[["最少需要{min}个字符","최소 {min} 글자 이상 필요"],["最大值为{max}","최댓값은 {max}"],["最多允许{max}个字符","{max} 글자까지 허용"],["格式不正确","형식이 올바르지 않습니다."],["验证失败","검증 실패"],["暂无数据","현재 데이터가 없습니다."],["加载中","로딩 중"],["上传 / 拍摄","업로드 / 촬영"],["请输入","입력해 주세요"],["请选择","선택해 주세요"],["小时","시간"],["分钟","분"],["秒数","초"],["确定","확인"],["取消","취소"],["年","년"],["月","월"],["日","일"],["时","시"],["分","분"],["秒","초"],["开始日期","시작 날짜"],["结束日期","종료 날짜"],["至","~"],["今天","오늘"],["近7天","지난 7일"],["近30天","최근 30일"],["近90天","최근 90일"],["近一年","지난 1년"],["请选择完整时间范围","완전한 시간 범위를 선택하세요"],["开始日期不能大于结束日期","시작 날짜는 종료 날짜보다 클 수 없습니다"],["提示","힌트"],["没有更多了","더 이상 없습니다"],["下拉刷新","드롭다운으로 새로고침"],["释放立即刷新","즉시 새로고침을 위해 놓습니다"],["密码键盘","비밀번호 키보드"],["安全键盘,请放心输入","안전한 키보드, 안심하고 입력하세요"],["请输入内容","내용을 입력하세요"],["请输入{minlength}到{maxlength}位密码","{minlength}에서 {maxlength}자리 비밀번호를 입력하세요"],["最多输入{maxlength}位","최대 {maxlength}자리까지 입력 가능"],["数字键盘","숫자 키보드"],["身份证号码格式不正确","주민등록번호 형식이 올바르지 않습니다"],["车牌键盘","자동차 번호판 키보드"],["车牌号格式不正确","자동차 번호판 형식이 올바르지 않습니다"],["此字段为必填项","이 필드는 필수입니다"],["最小值为{min}","최소값은 {min}입니다"]]
|
||||
1
uni_modules/cool-ui/locale/zh-cn.json
Normal file
1
uni_modules/cool-ui/locale/zh-cn.json
Normal file
@@ -0,0 +1 @@
|
||||
[["加载中",""],["上传 / 拍摄",""],["请输入",""],["请选择",""],["小时",""],["分钟",""],["秒数",""],["确定",""],["取消",""],["年",""],["月",""],["日",""],["时",""],["分",""],["秒",""],["开始日期",""],["结束日期",""],["至",""],["今天",""],["近7天",""],["近30天",""],["近90天",""],["近一年",""],["请选择完整时间范围",""],["开始日期不能大于结束日期",""],["提示",""],["没有更多了",""],["下拉刷新",""],["释放立即刷新",""],["密码键盘",""],["安全键盘,请放心输入",""],["请输入内容",""],["请输入{minlength}到{maxlength}位密码",""],["最多输入{maxlength}位",""],["数字键盘",""],["身份证号码格式不正确",""],["车牌键盘",""],["车牌号格式不正确",""],["此字段为必填项",""],["最小值为{min}",""],["最少需要{min}个字符",""],["最大值为{max}",""],["最多允许{max}个字符",""],["格式不正确",""],["验证失败",""],["暂无数据",""]]
|
||||
1
uni_modules/cool-ui/locale/zh-tw.json
Normal file
1
uni_modules/cool-ui/locale/zh-tw.json
Normal file
@@ -0,0 +1 @@
|
||||
[["最少需要{min}个字符","最少需要{min}個字元"],["最大值为{max}","最大值為{max}"],["最多允许{max}个字符","最多允許{max}個字元"],["格式不正确","格式不正確"],["验证失败","驗證失敗"],["暂无数据","暂无資料"],["加载中","加載中"],["上传 / 拍摄","上傳 / 拍攝"],["请输入","請輸入"],["请选择","請選擇"],["小时","小時"],["分钟","分鐘"],["秒数","秒數"],["确定","確定"],["取消","取消"],["年","年"],["月","月"],["日","日"],["时","時"],["分","分"],["秒","秒"],["开始日期","開始日期"],["结束日期","結束日期"],["至","至"],["今天","今天"],["近7天","近7天"],["近30天","近30天"],["近90天","近90天"],["近一年","近一年"],["请选择完整时间范围","請選擇完整時間範圍"],["开始日期不能大于结束日期","開始日期不能大於結束日期"],["提示","提示"],["没有更多了","沒有更多了"],["下拉刷新","下拉刷新"],["释放立即刷新","釋放立即刷新"],["密码键盘","密碼鍵盤"],["安全键盘,请放心输入","安全鍵盤,請放心輸入"],["请输入内容","請輸入內容"],["请输入{minlength}到{maxlength}位密码","請輸入{minlength}到{maxlength}位密碼"],["最多输入{maxlength}位","最多輸入{maxlength}位"],["数字键盘","數字鍵盤"],["身份证号码格式不正确","身份證號碼格式不正確"],["车牌键盘","車牌鍵盤"],["车牌号格式不正确","車牌號格式不正確"],["此字段为必填项","此字段為必填項"],["最小值为{min}","最小值為{min}"]]
|
||||
Reference in New Issue
Block a user