提交 db033279 编写于 作者: fxy060608's avatar fxy060608

feat(i18n): unicloud-db

上级 b6abfa4d
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
"release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3" "release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-i18n": "^0.0.1", "@dcloudio/uni-i18n": "^0.0.2",
"base64-arraybuffer": "^0.2.0", "base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0", "intersection-observer": "^0.7.0",
"pako": "^1.0.11", "pako": "^1.0.11",
......
...@@ -2174,6 +2174,277 @@ var serviceContext = (function () { ...@@ -2174,6 +2174,277 @@ var serviceContext = (function () {
pageScrollTo: pageScrollTo pageScrollTo: pageScrollTo
}); });
const isObject$1 = (val) => val !== null && typeof val === 'object';
class BaseFormatter {
constructor() {
this._caches = Object.create(null);
}
interpolate(message, values) {
if (!values) {
return [message];
}
let tokens = this._caches[message];
if (!tokens) {
tokens = parse(message);
this._caches[message] = tokens;
}
return compile(tokens, values);
}
}
const RE_TOKEN_LIST_VALUE = /^(?:\d)+/;
const RE_TOKEN_NAMED_VALUE = /^(?:\w)+/;
function parse(format) {
const tokens = [];
let position = 0;
let text = '';
while (position < format.length) {
let char = format[position++];
if (char === '{') {
if (text) {
tokens.push({ type: 'text', value: text });
}
text = '';
let sub = '';
char = format[position++];
while (char !== undefined && char !== '}') {
sub += char;
char = format[position++];
}
const isClosed = char === '}';
const type = RE_TOKEN_LIST_VALUE.test(sub)
? 'list'
: isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
? 'named'
: 'unknown';
tokens.push({ value: sub, type });
}
else if (char === '%') {
// when found rails i18n syntax, skip text capture
if (format[position] !== '{') {
text += char;
}
}
else {
text += char;
}
}
text && tokens.push({ type: 'text', value: text });
return tokens;
}
function compile(tokens, values) {
const compiled = [];
let index = 0;
const mode = Array.isArray(values)
? 'list'
: isObject$1(values)
? 'named'
: 'unknown';
if (mode === 'unknown') {
return compiled;
}
while (index < tokens.length) {
const token = tokens[index];
switch (token.type) {
case 'text':
compiled.push(token.value);
break;
case 'list':
compiled.push(values[parseInt(token.value, 10)]);
break;
case 'named':
if (mode === 'named') {
compiled.push(values[token.value]);
}
else {
if (process.env.NODE_ENV !== 'production') {
console.warn(`Type of token '${token.type}' and format of value '${mode}' don't match!`);
}
}
break;
case 'unknown':
if (process.env.NODE_ENV !== 'production') {
console.warn(`Detect 'unknown' type of token!`);
}
break;
}
index++;
}
return compiled;
}
let curLocale = 'en';
let fallbackLocale = 'en';
let curMessages = {};
let messages = {};
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
const hasOwn$1 = (val, key) => hasOwnProperty$1.call(val, key);
const defaultFormatter = new BaseFormatter();
function include(str, parts) {
return !!parts.find((part) => str.indexOf(part) !== -1);
}
function startsWith(str, parts) {
return parts.find((part) => str.indexOf(part) === 0);
}
function normalizeLocale(locale) {
if (!locale) {
return fallbackLocale;
}
locale = locale.trim().replace(/_/g, '-');
if (messages[locale]) {
return locale;
}
locale = locale.toLowerCase();
if (locale.indexOf('zh') === 0) {
if (locale.indexOf('-hans') !== -1) {
return 'zh-Hans';
}
if (locale.indexOf('-hant') !== -1) {
return 'zh-Hant';
}
if (include(locale, ['-tw', '-hk', '-mo', '-cht'])) {
return 'zh-Hant';
}
return 'zh-Hans';
}
const lang = startsWith(locale, ['en', 'fr', 'es']);
if (lang) {
return lang;
}
return fallbackLocale;
}
var index = {
init(options) {
if (options.fallbackLocale) {
fallbackLocale = options.fallbackLocale;
}
messages = options.messages;
this.setLocale(options.locale);
},
setLocale(locale) {
curLocale = normalizeLocale(locale);
curMessages = messages[curLocale];
},
getLocale() {
return curLocale;
},
t(key, values) {
if (!hasOwn$1(curMessages, key)) {
console.warn(`Cannot translate the value of keypath ${key}. Use the value of keypath as default.`);
return key;
}
return defaultFormatter.interpolate(curMessages[key], values).join('');
},
};
var en = {
"uni.showActionSheet.cancel": "cancel",
"uni.showToast.unpaired": "Please note showToast must be paired with hideToast",
"uni.showLoading.unpaired": "Please note showLoading must be paired with hideLoading",
"uni.showModal.cancel": "cancel",
"uni.showModal.confirm": "confirm",
"uni.button.feedback.title": "feedback",
"uni.button.feedback.send": "send"
};
var es = {
"uni.showActionSheet.cancel": "cancelar",
"uni.showToast.unpaired": "Tenga en cuenta que showToast debe estar emparejado con hideToast",
"uni.showLoading.unpaired": "Tenga en cuenta que showLoading debe estar emparejado con hideLoading",
"uni.showModal.cancel": "cancelar",
"uni.showModal.confirm": "confirmar",
"uni.button.feedback.title": "realimentación",
"uni.button.feedback.send": "enviar"
};
var fr = {
"uni.showActionSheet.cancel": "Annuler",
"uni.showToast.unpaired": "Veuillez noter que showToast doit être associé à hideToast",
"uni.showLoading.unpaired": "Veuillez noter que showLoading doit être associé à hideLoading",
"uni.showModal.cancel": "Annuler",
"uni.showModal.confirm": "confirmer",
"uni.button.feedback.title": "retour d'information",
"uni.button.feedback.send": "envoyer"
};
var zhHans = {
"uni.showActionSheet.cancel": "取消",
"uni.showToast.unpaired": "请注意 showToast 与 hideToast 必须配对使用",
"uni.showLoading.unpaired": "请注意 showLoading 与 hideLoading 必须配对使用",
"uni.showModal.cancel": "取消",
"uni.showModal.confirm": "确认",
"uni.button.feedback.title": "问题反馈",
"uni.button.feedback.send": "发送"
};
var zhHant = {
"uni.showActionSheet.cancel": "取消",
"uni.showToast.unpaired": "請注意 showToast 與 hideToast 必須配對使用",
"uni.showLoading.unpaired": "請注意 showLoading 與 hideLoading 必須配對使用",
"uni.showModal.cancel": "取消",
"uni.showModal.confirm": "確認",
"uni.button.feedback.title": "問題反饋",
"uni.button.feedback.send": "發送"
};
const messages$1 = {
en,
es,
fr,
'zh-Hans': zhHans,
'zh-Hant': zhHant
};
const fallbackLocale$1 = 'en';
function initI18n (locale, onChange) {
index.init({
locale,
fallbackLocale: fallbackLocale$1,
messages: messages$1
});
if (onChange) {
index.watchLocale((newLocale, oldLocale) => {
onChange(newLocale, oldLocale);
});
}
}
function initLocaleWatcher (appVm) {
appVm.$i18n.vm.$watch('locale', (newLocale) => {
index.setLocale(newLocale);
}, {
immediate: true
});
}
function t (key, values) {
if (__VIEW__) {
return index.t(key, values)
}
const appVm = getApp().$vm;
if (!appVm.$t) {
/* eslint-disable no-func-assign */
t = function (key, values) {
return index.t(key, values)
};
} else {
initLocaleWatcher(appVm);
/* eslint-disable no-func-assign */
t = function (key, values) {
const $i18n = appVm.$i18n;
const silentTranslationWarn = $i18n.silentTranslationWarn;
$i18n.silentTranslationWarn = true;
const msg = appVm.$t(key, values);
$i18n.silentTranslationWarn = silentTranslationWarn;
if (msg !== key) {
return msg
}
return index.t(key, values)
};
}
return t(key, values)
}
const showModal = { const showModal = {
title: { title: {
type: String, type: String,
...@@ -2189,7 +2460,9 @@ var serviceContext = (function () { ...@@ -2189,7 +2460,9 @@ var serviceContext = (function () {
}, },
cancelText: { cancelText: {
type: String, type: String,
default: '取消' default () {
return t('uni.showModal.cancel')
}
}, },
cancelColor: { cancelColor: {
type: String, type: String,
...@@ -2197,7 +2470,9 @@ var serviceContext = (function () { ...@@ -2197,7 +2470,9 @@ var serviceContext = (function () {
}, },
confirmText: { confirmText: {
type: String, type: String,
default: '确定' default () {
return t('uni.showModal.confirm')
}
}, },
confirmColor: { confirmColor: {
type: String, type: String,
...@@ -5545,12 +5820,12 @@ var serviceContext = (function () { ...@@ -5545,12 +5820,12 @@ var serviceContext = (function () {
}, fail); }, fail);
} }
let index = 0; let index$1 = 0;
function saveFile$1 ({ function saveFile$1 ({
tempFilePath tempFilePath
} = {}, callbackId) { } = {}, callbackId) {
const errorCallback = warpPlusErrorCallback(callbackId, 'saveFile'); const errorCallback = warpPlusErrorCallback(callbackId, 'saveFile');
const fileName = `${Date.now()}${index++}${getExtName(tempFilePath)}`; const fileName = `${Date.now()}${index$1++}${getExtName(tempFilePath)}`;
plus.io.resolveLocalFileSystemURL(tempFilePath, entry => { // 读取临时文件 FileEntry plus.io.resolveLocalFileSystemURL(tempFilePath, entry => { // 读取临时文件 FileEntry
getSavedFileDir(dir => { getSavedFileDir(dir => {
...@@ -6533,7 +6808,7 @@ var serviceContext = (function () { ...@@ -6533,7 +6808,7 @@ var serviceContext = (function () {
delete requestTasks[requestTaskId]; delete requestTasks[requestTaskId];
}; };
const cookiesPrase = header => { const cookiesParse = header => {
let cookiesStr = header['Set-Cookie'] || header['set-cookie']; let cookiesStr = header['Set-Cookie'] || header['set-cookie'];
let cookiesArr = []; let cookiesArr = [];
if (!cookiesStr) { if (!cookiesStr) {
...@@ -6544,7 +6819,7 @@ var serviceContext = (function () { ...@@ -6544,7 +6819,7 @@ var serviceContext = (function () {
} }
const handleCookiesArr = cookiesStr.split(';'); const handleCookiesArr = cookiesStr.split(';');
for (let i = 0; i < handleCookiesArr.length; i++) { for (let i = 0; i < handleCookiesArr.length; i++) {
if (handleCookiesArr[i].indexOf('Expires=') !== -1) { if (handleCookiesArr[i].indexOf('Expires=') !== -1 || handleCookiesArr[i].indexOf('expires=') !== -1) {
cookiesArr.push(handleCookiesArr[i].replace(',', '')); cookiesArr.push(handleCookiesArr[i].replace(',', ''));
} else { } else {
cookiesArr.push(handleCookiesArr[i]); cookiesArr.push(handleCookiesArr[i]);
...@@ -6626,7 +6901,8 @@ var serviceContext = (function () { ...@@ -6626,7 +6901,8 @@ var serviceContext = (function () {
ok, ok,
status, status,
data, data,
headers headers,
errorMsg
}) => { }) => {
if (aborted) { if (aborted) {
return return
...@@ -6642,14 +6918,18 @@ var serviceContext = (function () { ...@@ -6642,14 +6918,18 @@ var serviceContext = (function () {
data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer$2(data) : data, data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer$2(data) : data,
statusCode, statusCode,
header: headers, header: headers,
cookies: cookiesPrase(headers) cookies: cookiesParse(headers)
}); });
} else { } else {
let errMsg = 'abort statusCode:' + statusCode;
if (errorMsg) {
errMsg = errMsg + ' ' + errorMsg;
}
publishStateChange$1({ publishStateChange$1({
requestTaskId, requestTaskId,
state: 'fail', state: 'fail',
statusCode, statusCode,
errMsg: 'abort statusCode:' + statusCode errMsg
}); });
} }
}); });
...@@ -9526,7 +9806,9 @@ var serviceContext = (function () { ...@@ -9526,7 +9806,9 @@ var serviceContext = (function () {
let timeout; let timeout;
function showLoading$1 (args) { function showLoading$1 (args) {
return callApiSync(showToast$1, Object.assign({}, args, { type: 'loading' }), 'showToast', 'showLoading') return callApiSync(showToast$1, Object.assign({}, args, {
type: 'loading'
}), 'showToast', 'showLoading')
} }
function hideLoading () { function hideLoading () {
...@@ -9626,10 +9908,10 @@ var serviceContext = (function () { ...@@ -9626,10 +9908,10 @@ var serviceContext = (function () {
title = '', title = '',
content = '', content = '',
showCancel = true, showCancel = true,
cancelText = '取消', cancelText,
cancelColor = '#000000', cancelColor,
confirmText = '确定', confirmText,
confirmColor = '#3CC51F' confirmColor
} = {}, callbackId) { } = {}, callbackId) {
content = content || ' '; content = content || ' ';
plus.nativeUI.confirm(content, (e) => { plus.nativeUI.confirm(content, (e) => {
...@@ -9666,7 +9948,9 @@ var serviceContext = (function () { ...@@ -9666,7 +9948,9 @@ var serviceContext = (function () {
options.cancel = ''; options.cancel = '';
plus.nativeUI.actionSheet(Object.assign(options, { popover }), (e) => { plus.nativeUI.actionSheet(Object.assign(options, {
popover
}), (e) => {
if (e.index > 0) { if (e.index > 0) {
invoke$1(callbackId, { invoke$1(callbackId, {
errMsg: 'showActionSheet:ok', errMsg: 'showActionSheet:ok',
...@@ -12039,7 +12323,7 @@ var serviceContext = (function () { ...@@ -12039,7 +12323,7 @@ var serviceContext = (function () {
// misrepresented as being the original software. // misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution. // 3. This notice may not be removed or altered from any source distribution.
var messages = { var messages$2 = {
2: 'need dictionary', /* Z_NEED_DICT 2 */ 2: 'need dictionary', /* Z_NEED_DICT 2 */
1: 'stream end', /* Z_STREAM_END 1 */ 1: 'stream end', /* Z_STREAM_END 1 */
0: '', /* Z_OK 0 */ 0: '', /* Z_OK 0 */
...@@ -12174,7 +12458,7 @@ var serviceContext = (function () { ...@@ -12174,7 +12458,7 @@ var serviceContext = (function () {
var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
function err(strm, errorCode) { function err(strm, errorCode) {
strm.msg = messages[errorCode]; strm.msg = messages$2[errorCode];
return errorCode; return errorCode;
} }
...@@ -14322,7 +14606,7 @@ var serviceContext = (function () { ...@@ -14322,7 +14606,7 @@ var serviceContext = (function () {
); );
if (status !== Z_OK$1) { if (status !== Z_OK$1) {
throw new Error(messages[status]); throw new Error(messages$2[status]);
} }
if (opt.header) { if (opt.header) {
...@@ -14344,7 +14628,7 @@ var serviceContext = (function () { ...@@ -14344,7 +14628,7 @@ var serviceContext = (function () {
status = deflate_1.deflateSetDictionary(this.strm, dict); status = deflate_1.deflateSetDictionary(this.strm, dict);
if (status !== Z_OK$1) { if (status !== Z_OK$1) {
throw new Error(messages[status]); throw new Error(messages$2[status]);
} }
this._dict_set = true; this._dict_set = true;
...@@ -14522,7 +14806,7 @@ var serviceContext = (function () { ...@@ -14522,7 +14806,7 @@ var serviceContext = (function () {
deflator.push(input, true); deflator.push(input, true);
// That will never happens, if you don't cheat with options :) // That will never happens, if you don't cheat with options :)
if (deflator.err) { throw deflator.msg || messages[deflator.err]; } if (deflator.err) { throw deflator.msg || messages$2[deflator.err]; }
return deflator.result; return deflator.result;
} }
...@@ -17074,7 +17358,7 @@ var serviceContext = (function () { ...@@ -17074,7 +17358,7 @@ var serviceContext = (function () {
); );
if (status !== constants.Z_OK) { if (status !== constants.Z_OK) {
throw new Error(messages[status]); throw new Error(messages$2[status]);
} }
this.header = new gzheader(); this.header = new gzheader();
...@@ -17092,7 +17376,7 @@ var serviceContext = (function () { ...@@ -17092,7 +17376,7 @@ var serviceContext = (function () {
if (opt.raw) { //In raw mode we need to set the dictionary early if (opt.raw) { //In raw mode we need to set the dictionary early
status = inflate_1.inflateSetDictionary(this.strm, opt.dictionary); status = inflate_1.inflateSetDictionary(this.strm, opt.dictionary);
if (status !== constants.Z_OK) { if (status !== constants.Z_OK) {
throw new Error(messages[status]); throw new Error(messages$2[status]);
} }
} }
} }
...@@ -17322,7 +17606,7 @@ var serviceContext = (function () { ...@@ -17322,7 +17606,7 @@ var serviceContext = (function () {
inflator.push(input, true); inflator.push(input, true);
// That will never happens, if you don't cheat with options :) // That will never happens, if you don't cheat with options :)
if (inflator.err) { throw inflator.msg || messages[inflator.err]; } if (inflator.err) { throw inflator.msg || messages$2[inflator.err]; }
return inflator.result; return inflator.result;
} }
...@@ -20481,7 +20765,7 @@ var serviceContext = (function () { ...@@ -20481,7 +20765,7 @@ var serviceContext = (function () {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log('[uni-app] registerApp'); console.log('[uni-app] registerApp');
} }
appVm.$$t = t;
appCtx = appVm; appCtx = appVm;
appCtx.$vm = appVm; appCtx.$vm = appVm;
...@@ -20491,6 +20775,9 @@ var serviceContext = (function () { ...@@ -20491,6 +20775,9 @@ var serviceContext = (function () {
// merge globalData // merge globalData
appCtx.globalData = Object.assign(globalData, appCtx.globalData); appCtx.globalData = Object.assign(globalData, appCtx.globalData);
// TODO
initI18n(plus.os.language);
initOn(UniServiceJSBridge.on, { initOn(UniServiceJSBridge.on, {
getApp: getApp$1, getApp: getApp$1,
getCurrentPages: getCurrentPages$1 getCurrentPages: getCurrentPages$1
...@@ -20765,7 +21052,9 @@ var serviceContext = (function () { ...@@ -20765,7 +21052,9 @@ var serviceContext = (function () {
onMethod('onKeyboardHeightChange', res => { onMethod('onKeyboardHeightChange', res => {
keyboardHeight = res.height; keyboardHeight = res.height;
if (keyboardHeight > 0) { if (keyboardHeight > 0) {
onKeyboardShow && onKeyboardShow(); const callback = onKeyboardShow;
onKeyboardShow = null;
callback && callback();
} }
}); });
...@@ -21308,6 +21597,7 @@ var serviceContext = (function () { ...@@ -21308,6 +21597,7 @@ var serviceContext = (function () {
return { return {
version: VD_SYNC_VERSION, version: VD_SYNC_VERSION,
locale: plus.os.language, // TODO
disableScroll, disableScroll,
onPageScroll, onPageScroll,
onPageReachBottom, onPageReachBottom,
...@@ -21340,6 +21630,10 @@ var serviceContext = (function () { ...@@ -21340,6 +21630,10 @@ var serviceContext = (function () {
} }
if (this.mpType === 'page') { if (this.mpType === 'page') {
const app = getApp();
if (app.$vm && app.$vm.$i18n) {
this._i18n = app.$vm.$i18n;
}
this.$scope = this.$options.pageInstance; this.$scope = this.$options.pageInstance;
this.$scope.$vm = this; this.$scope.$vm = this;
delete this.$options.pageInstance; delete this.$options.pageInstance;
...@@ -21452,7 +21746,7 @@ var serviceContext = (function () { ...@@ -21452,7 +21746,7 @@ var serviceContext = (function () {
UniServiceJSBridge.invokeCallbackHandler = invokeCallbackHandler; UniServiceJSBridge.invokeCallbackHandler = invokeCallbackHandler;
UniServiceJSBridge.removeCallbackHandler = removeCallbackHandler; UniServiceJSBridge.removeCallbackHandler = removeCallbackHandler;
var index$1 = { var index$2 = {
__vuePlugin: vuePlugin, __vuePlugin: vuePlugin,
__definePage: definePage, __definePage: definePage,
__registerApp: registerApp, __registerApp: registerApp,
...@@ -21462,7 +21756,7 @@ var serviceContext = (function () { ...@@ -21462,7 +21756,7 @@ var serviceContext = (function () {
getCurrentPages: getCurrentPages$1 getCurrentPages: getCurrentPages$1
}; };
return index$1; return index$2;
}()); }());
......
{
"uniCloud.component.add.success": "Success",
"uniCloud.component.update.success": "Success",
"uniCloud.component.remove.showModal.title": "Tips",
"uniCloud.component.remove.showModal.content": "是否删除该数据"
}
{
"uniCloud.component.add.success": "新增成功",
"uniCloud.component.update.success": "修改成功",
"uniCloud.component.remove.showModal.title": "提示",
"uniCloud.component.remove.showModal.content": "是否删除该数据"
}
{
"uniCloud.component.add.success": "新增成功",
"uniCloud.component.update.success": "修改成功",
"uniCloud.component.remove.showModal.title": "提示",
"uniCloud.component.remove.showModal.content": "是否删除该数据"
}
{
"uniCloud.component.add.success": "新增成功",
"uniCloud.component.update.success": "修改成功",
"uniCloud.component.remove.showModal.title": "提示",
"uniCloud.component.remove.showModal.content": "是否删除该数据"
}
{
"uniCloud.component.add.success": "新增成功",
"uniCloud.component.update.success": "修改成功",
"uniCloud.component.remove.showModal.title": "提示",
"uniCloud.component.remove.showModal.content": "是否刪除數據"
}
...@@ -12,6 +12,29 @@ ...@@ -12,6 +12,29 @@
</template> </template>
<script> <script>
import defaultMessage from './i18n/zh-Hans.json'
function createTranslate (defaultMessage) {
let t = (key, values) => {
const appVm = getApp().$vm
if (appVm && appVm.$t) {
t = (key, values) => {
const msg = appVm.$t(key, values)
if (msg !== key) {
return msg
}
return defaultMessage[key]
}
} else {
t = (key, values) => {
return defaultMessage[key]
}
}
return t(key, values)
}
return t
}
const t = createTranslate(defaultMessage)
const events = { const events = {
load: 'load', load: 'load',
error: 'error' error: 'error'
...@@ -280,7 +303,7 @@ export default { ...@@ -280,7 +303,7 @@ export default {
success && success(res) success && success(res)
if (showToast) { if (showToast) {
uni.showToast({ uni.showToast({
title: toastTitle || '新增成功' title: toastTitle || t('uniCloud.component.add.success')
}) })
} }
}).catch((err) => { }).catch((err) => {
...@@ -306,8 +329,8 @@ export default { ...@@ -306,8 +329,8 @@ export default {
return return
} }
uni.showModal({ uni.showModal({
title: confirmTitle || '提示', title: confirmTitle || t('uniCloud.component.remove.showModal.title'),
content: confirmContent || '是否删除该数据', content: confirmContent || t('uniCloud.component.remove.showModal.content'),
showCancel: true, showCancel: true,
success: (res) => { success: (res) => {
if (!res.confirm) { if (!res.confirm) {
...@@ -336,7 +359,7 @@ export default { ...@@ -336,7 +359,7 @@ export default {
success && success(res) success && success(res)
if (showToast) { if (showToast) {
uni.showToast({ uni.showToast({
title: toastTitle || '修改成功' title: toastTitle || t('uniCloud.component.update.success')
}) })
} }
}).catch((err) => { }).catch((err) => {
......
{'cs_common':{},'cs_':{'cs_1':'新增成功','cs_2':'提示','cs_3':'是否删除该数据','cs_4':'修改成功'}}
\ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@dcloudio/uni-i18n": "^0.0.2",
"base64-arraybuffer": "^0.2.0", "base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0", "intersection-observer": "^0.7.0",
"pako": "^1.0.11", "pako": "^1.0.11",
......
...@@ -29,8 +29,8 @@ export function initI18n (locale, onChange) { ...@@ -29,8 +29,8 @@ export function initI18n (locale, onChange) {
} }
} }
function initLocaleWatcher (app) { function initLocaleWatcher (appVm) {
app.$i18n.vm.$watch('locale', (newLocale) => { appVm.$i18n.vm.$watch('locale', (newLocale) => {
i18n.setLocale(newLocale) i18n.setLocale(newLocale)
}, { }, {
immediate: true immediate: true
...@@ -41,20 +41,20 @@ export function t (key, values) { ...@@ -41,20 +41,20 @@ export function t (key, values) {
if (__VIEW__) { if (__VIEW__) {
return i18n.t(key, values) return i18n.t(key, values)
} }
const app = getApp() const appVm = getApp().$vm
if (!app.$t) { if (!appVm.$t) {
/* eslint-disable no-func-assign */ /* eslint-disable no-func-assign */
t = function (key, values) { t = function (key, values) {
return i18n.t(key, values) return i18n.t(key, values)
} }
} else { } else {
initLocaleWatcher(app) initLocaleWatcher(appVm)
/* eslint-disable no-func-assign */ /* eslint-disable no-func-assign */
t = function (key, values) { t = function (key, values) {
const $i18n = app.$i18n const $i18n = appVm.$i18n
const silentTranslationWarn = $i18n.silentTranslationWarn const silentTranslationWarn = $i18n.silentTranslationWarn
$i18n.silentTranslationWarn = true $i18n.silentTranslationWarn = true
const msg = app.$t(key, values) const msg = appVm.$t(key, values)
$i18n.silentTranslationWarn = silentTranslationWarn $i18n.silentTranslationWarn = silentTranslationWarn
if (msg !== key) { if (msg !== key) {
return msg return msg
......
...@@ -69,7 +69,8 @@ export function getCurrentPages (isAll = false, ignoreError = false) { ...@@ -69,7 +69,8 @@ export function getCurrentPages (isAll = false, ignoreError = false) {
} }
export default function createApp (vm, routes) { export default function createApp (vm, routes) {
appVm = vm appVm = vm
appVm.$vm = vm
appVm.$$t = t appVm.$$t = t
appVm.globalData = appVm.$options.globalData || {} appVm.globalData = appVm.$options.globalData || {}
......
...@@ -743,10 +743,10 @@ ...@@ -743,10 +743,10 @@
exec-sh "^0.3.2" exec-sh "^0.3.2"
minimist "^1.2.0" minimist "^1.2.0"
"@dcloudio/uni-i18n@^0.0.1": "@dcloudio/uni-i18n@^0.0.2":
version "0.0.1" version "0.0.2"
resolved "https://registry.yarnpkg.com/@dcloudio/uni-i18n/-/uni-i18n-0.0.1.tgz#98367f8d4ba5d50ba7d60c9ab78cff27bfc0338b" resolved "https://registry.yarnpkg.com/@dcloudio/uni-i18n/-/uni-i18n-0.0.2.tgz#5e5dcfd473d9bec15bc0b7ac5fc1c419a764ff02"
integrity sha512-4zD/+ZkMUo7puUwEyEhP134XBqEhADyOCw9PBS50MxUiuxTkWH0tzcZFJr4CV72NF9v3V9z+8IiFExxu+RVxoA== integrity sha512-YIGeLMHBtTFnFFxDi7NUnFwSP9q56NSL2Ys8Pn6jy1Tomn8UgjWt/gC8JNI85unJoYdFe2o6RMxwjyJ/EVP1Pg==
"@hapi/address@2.x.x": "@hapi/address@2.x.x":
version "2.1.4" version "2.1.4"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册