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

fix(i18n): custom locale

上级 2d998b28
...@@ -18,6 +18,11 @@ if (process.env.UNI_VIEW !== 'true') { ...@@ -18,6 +18,11 @@ if (process.env.UNI_VIEW !== 'true') {
commonjs2: 'vue-router', commonjs2: 'vue-router',
root: 'VueRouter' root: 'VueRouter'
} }
externals['@dcloudio/uni-i18n'] = {
commonjs: '@dcloudio/uni-i18n',
commonjs2: '@dcloudio/uni-i18n',
root: '@dcloudio/uni-i18n'
}
} }
const alias = { const alias = {
......
...@@ -64,6 +64,7 @@ var serviceContext = (function () { ...@@ -64,6 +64,7 @@ var serviceContext = (function () {
'chooseImage', 'chooseImage',
'chooseFile', 'chooseFile',
'previewImage', 'previewImage',
'closePreviewImage',
'getImageInfo', 'getImageInfo',
'getVideoInfo', 'getVideoInfo',
'saveImageToPhotosAlbum', 'saveImageToPhotosAlbum',
...@@ -234,6 +235,7 @@ var serviceContext = (function () { ...@@ -234,6 +235,7 @@ var serviceContext = (function () {
'preLogin', 'preLogin',
'closeAuthView', 'closeAuthView',
'getCheckBoxState', 'getCheckBoxState',
'getUniverifyManager',
'share', 'share',
'shareWithSystem', 'shareWithSystem',
'showShareMenu', 'showShareMenu',
...@@ -253,7 +255,8 @@ var serviceContext = (function () { ...@@ -253,7 +255,8 @@ var serviceContext = (function () {
'sendNativeEvent', 'sendNativeEvent',
'preloadPage', 'preloadPage',
'unPreloadPage', 'unPreloadPage',
'loadSubPackage' 'loadSubPackage',
'sendHostEvent'
]; ];
const ad = [ const ad = [
...@@ -1534,7 +1537,7 @@ var serviceContext = (function () { ...@@ -1534,7 +1537,7 @@ var serviceContext = (function () {
"uni.chooseVideo.cancel": "Cancel", "uni.chooseVideo.cancel": "Cancel",
"uni.chooseVideo.sourceType.album": "Album", "uni.chooseVideo.sourceType.album": "Album",
"uni.chooseVideo.sourceType.camera": "Camera", "uni.chooseVideo.sourceType.camera": "Camera",
"uni.previewImage.cancel": "Cancel", "uni.chooseFile.notUserActivation": "File chooser dialog can only be shown with a user activation",
"uni.previewImage.button.save": "Save Image", "uni.previewImage.button.save": "Save Image",
"uni.previewImage.save.success": "Saved successfully", "uni.previewImage.save.success": "Saved successfully",
"uni.previewImage.save.fail": "Save failed", "uni.previewImage.save.fail": "Save failed",
...@@ -1569,6 +1572,7 @@ var serviceContext = (function () { ...@@ -1569,6 +1572,7 @@ var serviceContext = (function () {
"uni.chooseVideo.cancel": "Cancelar", "uni.chooseVideo.cancel": "Cancelar",
"uni.chooseVideo.sourceType.album": "Álbum", "uni.chooseVideo.sourceType.album": "Álbum",
"uni.chooseVideo.sourceType.camera": "Cámara", "uni.chooseVideo.sourceType.camera": "Cámara",
"uni.chooseFile.notUserActivation": "El cuadro de diálogo del selector de archivos solo se puede mostrar con la activación del usuario",
"uni.previewImage.cancel": "Cancelar", "uni.previewImage.cancel": "Cancelar",
"uni.previewImage.button.save": "Guardar imagen", "uni.previewImage.button.save": "Guardar imagen",
"uni.previewImage.save.success": "Guardado exitosamente", "uni.previewImage.save.success": "Guardado exitosamente",
...@@ -1604,6 +1608,7 @@ var serviceContext = (function () { ...@@ -1604,6 +1608,7 @@ var serviceContext = (function () {
"uni.chooseVideo.cancel": "Annuler", "uni.chooseVideo.cancel": "Annuler",
"uni.chooseVideo.sourceType.album": "Album", "uni.chooseVideo.sourceType.album": "Album",
"uni.chooseVideo.sourceType.camera": "Caméra", "uni.chooseVideo.sourceType.camera": "Caméra",
"uni.chooseFile.notUserActivation": "La boîte de dialogue du sélecteur de fichier ne peut être affichée qu'avec une activation par l'utilisateur",
"uni.previewImage.cancel": "Annuler", "uni.previewImage.cancel": "Annuler",
"uni.previewImage.button.save": "Guardar imagen", "uni.previewImage.button.save": "Guardar imagen",
"uni.previewImage.save.success": "Enregistré avec succès", "uni.previewImage.save.success": "Enregistré avec succès",
...@@ -1639,6 +1644,7 @@ var serviceContext = (function () { ...@@ -1639,6 +1644,7 @@ var serviceContext = (function () {
"uni.chooseVideo.cancel": "取消", "uni.chooseVideo.cancel": "取消",
"uni.chooseVideo.sourceType.album": "从相册选择", "uni.chooseVideo.sourceType.album": "从相册选择",
"uni.chooseVideo.sourceType.camera": "拍摄", "uni.chooseVideo.sourceType.camera": "拍摄",
"uni.chooseFile.notUserActivation": "文件选择器对话框只能在由用户激活时显示",
"uni.previewImage.cancel": "取消", "uni.previewImage.cancel": "取消",
"uni.previewImage.button.save": "保存图像", "uni.previewImage.button.save": "保存图像",
"uni.previewImage.save.success": "保存图像到相册成功", "uni.previewImage.save.success": "保存图像到相册成功",
...@@ -1674,6 +1680,7 @@ var serviceContext = (function () { ...@@ -1674,6 +1680,7 @@ var serviceContext = (function () {
"uni.chooseVideo.cancel": "取消", "uni.chooseVideo.cancel": "取消",
"uni.chooseVideo.sourceType.album": "從相冊選擇", "uni.chooseVideo.sourceType.album": "從相冊選擇",
"uni.chooseVideo.sourceType.camera": "拍攝", "uni.chooseVideo.sourceType.camera": "拍攝",
"uni.chooseFile.notUserActivation": "文件選擇器對話框只能在由用戶激活時顯示",
"uni.previewImage.cancel": "取消", "uni.previewImage.cancel": "取消",
"uni.previewImage.button.save": "保存圖像", "uni.previewImage.button.save": "保存圖像",
"uni.previewImage.save.success": "保存圖像到相冊成功", "uni.previewImage.save.success": "保存圖像到相冊成功",
...@@ -1713,6 +1720,26 @@ var serviceContext = (function () { ...@@ -1713,6 +1720,26 @@ var serviceContext = (function () {
} }
} }
function initI18nMessages () {
if (!isEnableLocale()) {
return
}
const localeKeys = Object.keys(__uniConfig.locales);
if (localeKeys.length) {
localeKeys.forEach((locale) => {
const curMessages = messages[locale];
const userMessages = __uniConfig.locales[locale];
if (curMessages) {
Object.assign(curMessages, userMessages);
} else {
messages[locale] = userMessages;
}
});
}
}
initI18nMessages();
const i18n = initVueI18n( const i18n = initVueI18n(
locale, locale,
messages messages
...@@ -1808,7 +1835,7 @@ var serviceContext = (function () { ...@@ -1808,7 +1835,7 @@ var serviceContext = (function () {
} }
function isEnableLocale () { function isEnableLocale () {
return __uniConfig.locales && !!Object.keys(__uniConfig.locales).length return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
} }
function initNavigationBarI18n (navigationBar) { function initNavigationBarI18n (navigationBar) {
...@@ -1820,21 +1847,30 @@ var serviceContext = (function () { ...@@ -1820,21 +1847,30 @@ var serviceContext = (function () {
} }
} }
function initI18n () { // export function initI18n() {
const localeKeys = Object.keys(__uniConfig.locales || {}); // const localeKeys = Object.keys(__uniConfig.locales || {})
if (localeKeys.length) { // if (localeKeys.length) {
localeKeys.forEach((locale) => // localeKeys.forEach((locale) =>
i18n.add(locale, __uniConfig.locales[locale]) // i18n.add(locale, __uniConfig.locales[locale])
); // )
} // }
} // }
const setClipboardData = { const setClipboardData = {
beforeSuccess () { data: {
type: String,
required: true
},
showToast: {
type: Boolean,
default: true
},
beforeSuccess (res, params) {
if (!params.showToast) return
const title = t('uni.setClipboardData.success'); const title = t('uni.setClipboardData.success');
if (title) { if (title) {
uni.showToast({ uni.showToast({
title: t('uni.setClipboardData.success'), title,
icon: 'success', icon: 'success',
mask: false, mask: false,
style: { style: {
...@@ -2348,7 +2384,8 @@ var serviceContext = (function () { ...@@ -2348,7 +2384,8 @@ var serviceContext = (function () {
PUT: 'PUT', PUT: 'PUT',
DELETE: 'DELETE', DELETE: 'DELETE',
TRACE: 'TRACE', TRACE: 'TRACE',
CONNECT: 'CONNECT' CONNECT: 'CONNECT',
PATCH: 'PATCH'
}; };
const dataType = { const dataType = {
JSON: 'json' JSON: 'json'
...@@ -3604,7 +3641,7 @@ var serviceContext = (function () { ...@@ -3604,7 +3641,7 @@ var serviceContext = (function () {
const errMsg = res.errMsg; const errMsg = res.errMsg;
if (errMsg.indexOf(apiName + ':ok') === 0) { if (errMsg.indexOf(apiName + ':ok') === 0) {
isFn(beforeSuccess) && beforeSuccess(res); isFn(beforeSuccess) && beforeSuccess(res, params);
hasSuccess && success(res); hasSuccess && success(res);
...@@ -4325,6 +4362,8 @@ var serviceContext = (function () { ...@@ -4325,6 +4362,8 @@ var serviceContext = (function () {
return array.length > 1 ? '.' + array[array.length - 1] : '' return array.length > 1 ? '.' + array[array.length - 1] : ''
} }
const AUDIO_DEFAULT_CATEGORY = 'ambient';
const audios = {}; const audios = {};
const evts = ['play', 'canplay', 'ended', 'stop', 'waiting', 'seeking', 'seeked', 'pause']; const evts = ['play', 'canplay', 'ended', 'stop', 'waiting', 'seeking', 'seeked', 'pause'];
...@@ -4371,6 +4410,7 @@ var serviceContext = (function () { ...@@ -4371,6 +4410,7 @@ var serviceContext = (function () {
audio.src = ''; audio.src = '';
audio.volume = 1; audio.volume = 1;
audio.startTime = 0; audio.startTime = 0;
audio.setSessionCategory(AUDIO_DEFAULT_CATEGORY);
return { return {
errMsg: 'createAudioInstance:ok', errMsg: 'createAudioInstance:ok',
audioId audioId
...@@ -4397,7 +4437,8 @@ var serviceContext = (function () { ...@@ -4397,7 +4437,8 @@ var serviceContext = (function () {
autoplay = false, autoplay = false,
loop = false, loop = false,
obeyMuteSwitch, obeyMuteSwitch,
volume volume,
category = AUDIO_DEFAULT_CATEGORY
}) { }) {
const audio = audios[audioId]; const audio = audios[audioId];
if (audio) { if (audio) {
...@@ -4415,6 +4456,9 @@ var serviceContext = (function () { ...@@ -4415,6 +4456,9 @@ var serviceContext = (function () {
audio.volume = style.volume = volume; audio.volume = style.volume = volume;
} }
audio.setStyles(style); audio.setStyles(style);
if (category) {
audio.setSessionCategory(category);
}
initStateChage(audioId); initStateChage(audioId);
} }
return { return {
...@@ -6293,7 +6337,7 @@ var serviceContext = (function () { ...@@ -6293,7 +6337,7 @@ var serviceContext = (function () {
let deviceId; let deviceId;
function deviceId$1 () { function deviceId$1 () {
deviceId = deviceId || plus.runtime.getDCloudId(); deviceId = deviceId || plus.device.uuid;
return deviceId return deviceId
} }
...@@ -6710,7 +6754,8 @@ var serviceContext = (function () { ...@@ -6710,7 +6754,8 @@ var serviceContext = (function () {
function getLocation$1 ({ function getLocation$1 ({
type = 'wgs84', type = 'wgs84',
geocode = false, geocode = false,
altitude = false altitude = false,
highAccuracyExpireTime
} = {}, callbackId) { } = {}, callbackId) {
const errorCallback = warpPlusErrorCallback(callbackId, 'getLocation'); const errorCallback = warpPlusErrorCallback(callbackId, 'getLocation');
plus.geolocation.getCurrentPosition( plus.geolocation.getCurrentPosition(
...@@ -6726,7 +6771,8 @@ var serviceContext = (function () { ...@@ -6726,7 +6771,8 @@ var serviceContext = (function () {
errorCallback(e); errorCallback(e);
}, { }, {
geocode: geocode, geocode: geocode,
enableHighAccuracy: altitude enableHighAccuracy: altitude,
timeout: highAccuracyExpireTime
} }
); );
} }
...@@ -7206,6 +7252,19 @@ var serviceContext = (function () { ...@@ -7206,6 +7252,19 @@ var serviceContext = (function () {
} }
} }
function closePreviewImagePlus () {
try {
plus.nativeUI.closePreviewImage();
return {
errMsg: 'closePreviewImagePlus:ok'
}
} catch (error) {
return {
errMsg: 'closePreviewImagePlus:fail'
}
}
}
let recorder$1; let recorder$1;
let recordTimeout$1; let recordTimeout$1;
...@@ -7876,6 +7935,8 @@ var serviceContext = (function () { ...@@ -7876,6 +7935,8 @@ var serviceContext = (function () {
} }
} }
let univerifyManager;
function getService (provider) { function getService (provider) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.oauth.getServices(services => { plus.oauth.getServices(services => {
...@@ -7888,20 +7949,21 @@ var serviceContext = (function () { ...@@ -7888,20 +7949,21 @@ var serviceContext = (function () {
/** /**
* 微信登录 * 微信登录
*/ */
function login (params, callbackId) { function login (params, callbackId, plus = true) {
const provider = params.provider || 'weixin'; const provider = params.provider || 'weixin';
const errorCallback = warpPlusErrorCallback(callbackId, 'login'); const errorCallback = warpErrorCallback(callbackId, 'login', plus);
const authOptions = provider === 'apple' const authOptions = provider === 'apple'
? { scope: 'email' } ? { scope: 'email' }
: params.univerifyStyle : params.univerifyStyle
? { univerifyStyle: univerifyButtonsClickHandling(params.univerifyStyle, errorCallback) } ? { univerifyStyle: univerifyButtonsClickHandling(params.univerifyStyle, errorCallback) }
: {}; : {};
const _invoke = plus ? invoke$1 : callback.invoke;
getService(provider).then(service => { getService(provider).then(service => {
function login () { function login () {
if (params.onlyAuthorize && provider === 'weixin') { if (params.onlyAuthorize && provider === 'weixin') {
service.authorize(({ code }) => { service.authorize(({ code }) => {
invoke$1(callbackId, { _invoke(callbackId, {
code, code,
authResult: '', authResult: '',
errMsg: 'login:ok' errMsg: 'login:ok'
...@@ -7911,7 +7973,7 @@ var serviceContext = (function () { ...@@ -7911,7 +7973,7 @@ var serviceContext = (function () {
} }
service.login(res => { service.login(res => {
const authResult = res.target.authResult; const authResult = res.target.authResult;
invoke$1(callbackId, { _invoke(callbackId, {
code: authResult.code, code: authResult.code,
authResult: authResult, authResult: authResult,
errMsg: 'login:ok' errMsg: 'login:ok'
...@@ -8006,9 +8068,9 @@ var serviceContext = (function () { ...@@ -8006,9 +8068,9 @@ var serviceContext = (function () {
} }
} }
function preLogin$1 (params, callbackId) { function preLogin$1 (params, callbackId, plus) {
const successCallback = warpPlusSuccessCallback(callbackId, 'preLogin'); const successCallback = warpSuccessCallback(callbackId, 'preLogin', plus);
const errorCallback = warpPlusErrorCallback(callbackId, 'preLogin'); const errorCallback = warpErrorCallback(callbackId, 'preLogin', plus);
getService(params.provider).then(service => service.preLogin(successCallback, errorCallback)).catch(errorCallback); getService(params.provider).then(service => service.preLogin(successCallback, errorCallback)).catch(errorCallback);
} }
...@@ -8016,9 +8078,9 @@ var serviceContext = (function () { ...@@ -8016,9 +8078,9 @@ var serviceContext = (function () {
return getService('univerify').then(service => service.closeAuthView()) return getService('univerify').then(service => service.closeAuthView())
} }
function getCheckBoxState (params, callbackId) { function getCheckBoxState (params, callbackId, plus) {
const successCallback = warpPlusSuccessCallback(callbackId, 'getCheckBoxState'); const successCallback = warpSuccessCallback(callbackId, 'getCheckBoxState', plus);
const errorCallback = warpPlusErrorCallback(callbackId, 'getCheckBoxState'); const errorCallback = warpErrorCallback(callbackId, 'getCheckBoxState', plus);
try { try {
getService('univerify').then(service => { getService('univerify').then(service => {
const state = service.getCheckBoxState(); const state = service.getCheckBoxState();
...@@ -8033,19 +8095,19 @@ var serviceContext = (function () { ...@@ -8033,19 +8095,19 @@ var serviceContext = (function () {
* 一键登录自定义登陆按钮点击处理 * 一键登录自定义登陆按钮点击处理
*/ */
function univerifyButtonsClickHandling (univerifyStyle, errorCallback) { function univerifyButtonsClickHandling (univerifyStyle, errorCallback) {
if (univerifyStyle && isPlainObject(univerifyStyle) && univerifyStyle.buttons && if (isPlainObject(univerifyStyle) && isPlainObject(univerifyStyle.buttons) && toRawType(univerifyStyle.buttons.list) === 'Array') {
Object.prototype.toString.call(univerifyStyle.buttons.list) === '[object Array]' &&
univerifyStyle.buttons.list.length > 0
) {
univerifyStyle.buttons.list.forEach((button, index) => { univerifyStyle.buttons.list.forEach((button, index) => {
univerifyStyle.buttons.list[index].onclick = function () { univerifyStyle.buttons.list[index].onclick = function () {
closeAuthView().then(() => { const res = {
errorCallback({
code: '30008', code: '30008',
message: '用户点击了自定义按钮', message: '用户点击了自定义按钮',
index, index,
provider: button.provider provider: button.provider
}); };
isPlainObject(univerifyManager)
? univerifyManager._triggerUniverifyButtonsClick(res)
: closeAuthView().then(() => {
errorCallback(res);
}); });
}; };
}); });
...@@ -8053,6 +8115,76 @@ var serviceContext = (function () { ...@@ -8053,6 +8115,76 @@ var serviceContext = (function () {
return univerifyStyle return univerifyStyle
} }
class UniverifyManager {
constructor () {
this.provider = 'univerify';
this.eventName = 'api.univerifyButtonsClick';
}
close () {
closeAuthView();
}
login (options) {
this._warp((data, callbackId) => login(data, callbackId, false), this._getOptions(options));
}
getCheckBoxState (options) {
this._warp((_, callbackId) => getCheckBoxState(_, callbackId, false), options);
}
preLogin (options) {
this._warp((data, callbackId) => preLogin$1(data, callbackId, false), this._getOptions(options));
}
onButtonsClick (callback) {
UniServiceJSBridge.on(this.eventName, callback);
}
offButtonsClick (callback) {
UniServiceJSBridge.off(this.eventName, callback);
}
_triggerUniverifyButtonsClick (res) {
UniServiceJSBridge.emit(this.eventName, res);
}
_warp (fn, options) {
return callback.warp(fn)(this._getOptions(options))
}
_getOptions (options = {}) {
return Object.assign({}, options, { provider: this.provider })
}
}
function getUniverifyManager () {
return univerifyManager || (univerifyManager = new UniverifyManager())
}
function warpSuccessCallback (callbackId, name, plus = true) {
return plus
? warpPlusSuccessCallback(callbackId, name)
: (options) => {
callback.invoke(callbackId, Object.assign({}, options, {
errMsg: `${name}:ok`
}));
}
}
function warpErrorCallback (callbackId, name, plus = true) {
return plus
? warpPlusErrorCallback(callbackId, name)
: (error) => {
const { code = 0, message: errorMessage } = error;
callback.invoke(callbackId, {
errMsg: `${name}:fail ${errorMessage || ''}`,
errCode: code,
code
});
}
}
function requestPayment (params, callbackId) { function requestPayment (params, callbackId) {
const provider = params.provider; const provider = params.provider;
const errorCallback = warpPlusErrorCallback(callbackId, 'requestPayment'); const errorCallback = warpPlusErrorCallback(callbackId, 'requestPayment');
...@@ -8579,6 +8711,25 @@ var serviceContext = (function () { ...@@ -8579,6 +8711,25 @@ var serviceContext = (function () {
}); });
} }
const sendHostEvent = sendNativeEvent;
function navigateToMiniProgram (data, callbackId) {
sendHostEvent(
'navigateToUniMP',
data,
(res) => {
if (res.errMsg && res.errMsg.indexOf(':ok') === -1) {
return invoke$1(callbackId, {
errMsg: res.errMsg
})
}
invoke$1(callbackId, {
errMsg: 'navigateToMiniProgram:ok'
});
}
);
}
const VD_SYNC_VERSION = 2; const VD_SYNC_VERSION = 2;
const PAGE_CREATE = 2; const PAGE_CREATE = 2;
...@@ -10630,7 +10781,6 @@ var serviceContext = (function () { ...@@ -10630,7 +10781,6 @@ var serviceContext = (function () {
editable = false, editable = false,
placeholderText = '' placeholderText = ''
} = {}, callbackId) { } = {}, callbackId) {
// TODO 在 editable 为 true 时,content 应该是输入框中可修改内容。后续找客户端商量。
const buttons = showCancel ? [cancelText, confirmText] : [confirmText]; const buttons = showCancel ? [cancelText, confirmText] : [confirmText];
const tip = editable ? placeholderText : buttons; const tip = editable ? placeholderText : buttons;
...@@ -10751,6 +10901,11 @@ var serviceContext = (function () { ...@@ -10751,6 +10901,11 @@ var serviceContext = (function () {
pagePath, pagePath,
visible visible
}) { }) {
if (!isTabBarPage()) {
return {
errMsg: 'setTabBarItem:fail not TabBar page'
}
}
tabBar$1.setTabBarItem(index, text, iconPath, selectedIconPath, visible); tabBar$1.setTabBarItem(index, text, iconPath, selectedIconPath, visible);
const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath); const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath);
if (route) { if (route) {
...@@ -11654,6 +11809,7 @@ var serviceContext = (function () { ...@@ -11654,6 +11809,7 @@ var serviceContext = (function () {
getImageInfo: getImageInfo$1, getImageInfo: getImageInfo$1,
getVideoInfo: getVideoInfo$1, getVideoInfo: getVideoInfo$1,
previewImagePlus: previewImagePlus, previewImagePlus: previewImagePlus,
closePreviewImagePlus: closePreviewImagePlus,
operateRecorder: operateRecorder, operateRecorder: operateRecorder,
saveImageToPhotosAlbum: saveImageToPhotosAlbum$1, saveImageToPhotosAlbum: saveImageToPhotosAlbum$1,
saveVideoToPhotosAlbum: saveVideoToPhotosAlbum, saveVideoToPhotosAlbum: saveVideoToPhotosAlbum,
...@@ -11675,6 +11831,7 @@ var serviceContext = (function () { ...@@ -11675,6 +11831,7 @@ var serviceContext = (function () {
preLogin: preLogin$1, preLogin: preLogin$1,
closeAuthView: closeAuthView, closeAuthView: closeAuthView,
getCheckBoxState: getCheckBoxState, getCheckBoxState: getCheckBoxState,
getUniverifyManager: getUniverifyManager,
requestPayment: requestPayment, requestPayment: requestPayment,
subscribePush: subscribePush, subscribePush: subscribePush,
unsubscribePush: unsubscribePush, unsubscribePush: unsubscribePush,
...@@ -11690,6 +11847,8 @@ var serviceContext = (function () { ...@@ -11690,6 +11847,8 @@ var serviceContext = (function () {
onNativeEventReceive: onNativeEventReceive, onNativeEventReceive: onNativeEventReceive,
sendNativeEvent: sendNativeEvent, sendNativeEvent: sendNativeEvent,
loadSubPackage: loadSubPackage$2, loadSubPackage: loadSubPackage$2,
sendHostEvent: sendHostEvent,
navigateToMiniProgram: navigateToMiniProgram,
navigateBack: navigateBack$1, navigateBack: navigateBack$1,
navigateTo: navigateTo$1, navigateTo: navigateTo$1,
reLaunch: reLaunch$1, reLaunch: reLaunch$1,
...@@ -20130,9 +20289,14 @@ var serviceContext = (function () { ...@@ -20130,9 +20289,14 @@ var serviceContext = (function () {
return invokeMethod('previewImagePlus', args) return invokeMethod('previewImagePlus', args)
} }
function closePreviewImage (args = {}) {
return invokeMethod('closePreviewImagePlus', args)
}
var require_context_module_1_15 = /*#__PURE__*/Object.freeze({ var require_context_module_1_15 = /*#__PURE__*/Object.freeze({
__proto__: null, __proto__: null,
previewImage: previewImage$1 previewImage: previewImage$1,
closePreviewImage: closePreviewImage
}); });
const callbacks$8 = { const callbacks$8 = {
...@@ -22880,8 +23044,6 @@ var serviceContext = (function () { ...@@ -22880,8 +23044,6 @@ var serviceContext = (function () {
} }
}; };
initI18n();
// 挂靠在uni上,暂不做全局导出 // 挂靠在uni上,暂不做全局导出
uni$1.__$wx__ = wx; uni$1.__$wx__ = wx;
......
...@@ -364,6 +364,10 @@ ...@@ -364,6 +364,10 @@
] ]
] ]
], ],
"closePreviewImage": [
"/platforms/h5/service/api/media/preview-image.js",
[]
],
"getImageInfo": [ "getImageInfo": [
"/platforms/h5/service/api/media/get-image-info.js", "/platforms/h5/service/api/media/get-image-info.js",
[ [
......
...@@ -2,4 +2,4 @@ export const NAVBAR_HEIGHT = 44 ...@@ -2,4 +2,4 @@ export const NAVBAR_HEIGHT = 44
export const TABBAR_HEIGHT = 50 export const TABBAR_HEIGHT = 50
// 576:landscape phones,768:tablets,992:desktops,1200:large desktops // 576:landscape phones,768:tablets,992:desktops,1200:large desktops
export const RESPONSIVE_MIN_WIDTH = 768 export const RESPONSIVE_MIN_WIDTH = 768
export const DC_LOCALE = '__DC_LOCALE' export const UNI_STORAGE_LOCALE = 'UNI_LOCALE'
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
} from 'uni-shared' } from 'uni-shared'
import { import {
DC_LOCALE UNI_STORAGE_LOCALE
} from '../constants' } from '../constants'
import en from './en.json' import en from './en.json'
...@@ -27,7 +27,7 @@ const messages = { ...@@ -27,7 +27,7 @@ const messages = {
let locale let locale
if (__PLATFORM__ === 'h5') { if (__PLATFORM__ === 'h5') {
locale = (window.localStorage && localStorage[DC_LOCALE]) || __uniConfig.locale || navigator.language locale = (window.localStorage && localStorage[UNI_STORAGE_LOCALE]) || __uniConfig.locale || navigator.language
} else if (__PLATFORM__ === 'app-plus') { } else if (__PLATFORM__ === 'app-plus') {
if (typeof weex === 'object') { if (typeof weex === 'object') {
locale = weex.requireModule('plus').getLanguage() locale = weex.requireModule('plus').getLanguage()
...@@ -38,6 +38,26 @@ if (__PLATFORM__ === 'h5') { ...@@ -38,6 +38,26 @@ if (__PLATFORM__ === 'h5') {
locale = __GLOBAL__.getSystemInfoSync().language locale = __GLOBAL__.getSystemInfoSync().language
} }
function initI18nMessages () {
if (!isEnableLocale()) {
return
}
const localeKeys = Object.keys(__uniConfig.locales)
if (localeKeys.length) {
localeKeys.forEach((locale) => {
const curMessages = messages[locale]
const userMessages = __uniConfig.locales[locale]
if (curMessages) {
Object.assign(curMessages, userMessages)
} else {
messages[locale] = userMessages
}
})
}
}
initI18nMessages()
export const i18n = initVueI18n( export const i18n = initVueI18n(
locale, locale,
__PLATFORM__ === 'app-plus' || __PLATFORM__ === 'h5' ? messages : {} __PLATFORM__ === 'app-plus' || __PLATFORM__ === 'h5' ? messages : {}
...@@ -134,7 +154,7 @@ export function defineI18nProperty (obj, names) { ...@@ -134,7 +154,7 @@ export function defineI18nProperty (obj, names) {
} }
function isEnableLocale () { function isEnableLocale () {
return __uniConfig.locales && !!Object.keys(__uniConfig.locales).length return typeof __uniConfig !== 'undefined' && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
} }
export function initNavigationBarI18n (navigationBar) { export function initNavigationBarI18n (navigationBar) {
...@@ -166,11 +186,11 @@ export function initTabBarI18n (tabBar) { ...@@ -166,11 +186,11 @@ export function initTabBarI18n (tabBar) {
return tabBar return tabBar
} }
export function initI18n () { // export function initI18n() {
const localeKeys = Object.keys(__uniConfig.locales || {}) // const localeKeys = Object.keys(__uniConfig.locales || {})
if (localeKeys.length) { // if (localeKeys.length) {
localeKeys.forEach((locale) => // localeKeys.forEach((locale) =>
i18n.add(locale, __uniConfig.locales[locale]) // i18n.add(locale, __uniConfig.locales[locale])
) // )
} // }
} // }
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
i18n i18n
} from 'uni-helpers/i18n' } from 'uni-helpers/i18n'
import { import {
DC_LOCALE UNI_STORAGE_LOCALE
} from 'uni-helpers/constants' } from 'uni-helpers/constants'
export function getLocale () { export function getLocale () {
...@@ -35,7 +35,7 @@ export function setLocale (locale) { ...@@ -35,7 +35,7 @@ export function setLocale (locale) {
weex.requireModule('plus').setLanguage(locale) weex.requireModule('plus').setLanguage(locale)
} }
if (__PLATFORM__ === 'h5') { if (__PLATFORM__ === 'h5') {
window.localStorage && (localStorage[DC_LOCALE] = locale) window.localStorage && (localStorage[UNI_STORAGE_LOCALE] = locale)
} }
callbacks.forEach(callbackId => { callbacks.forEach(callbackId => {
invoke(callbackId, { locale }) invoke(callbackId, { locale })
......
...@@ -31,12 +31,6 @@ import { ...@@ -31,12 +31,6 @@ import {
import vuePlugin from './framework/plugins' import vuePlugin from './framework/plugins'
import {
initI18n
} from 'uni-helpers/i18n'
initI18n()
// 挂靠在uni上,暂不做全局导出 // 挂靠在uni上,暂不做全局导出
uni.__$wx__ = wx uni.__$wx__ = wx
......
...@@ -10,11 +10,6 @@ import { ...@@ -10,11 +10,6 @@ import {
getCurrentPages getCurrentPages
} }
from 'uni-core/service/plugins/app' from 'uni-core/service/plugins/app'
import {
initI18n
} from 'uni-helpers/i18n'
initI18n()
initOn(UniServiceJSBridge.on, { initOn(UniServiceJSBridge.on, {
getApp, getApp,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册