From 941001c098ab1b9201bbe30735018bab27ff1e30 Mon Sep 17 00:00:00 2001 From: "luk.lu" Date: Wed, 18 Aug 2021 17:18:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20localizeText,=20=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=8E=A5=E5=8F=97=20string=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=B9=B6=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 5de2627..e1a40bd 100644 --- a/index.js +++ b/index.js @@ -41,12 +41,14 @@ module.exports = { localizeText(i18nText) { // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page const thisPage = getCurrentPages()[getCurrentPages().length - 1] - if (thisPage.$store?.state?.i18n?.mylang) { - if (typeof(i18nText)==='object' && i18nText && i18nText[thisPage.$store.state.i18n.mylang]){ - return i18nText[thisPage.$store.state.i18n.mylang] - }else if (typeof(i18nText)==='undefined') { - return thisPage.i18nText[thisPage.$store.state.i18n.mylang] - } + if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) { + return i18nText[thisPage.$store.state.i18n.mylang] || '' + } + if (!i18nText && typeof(thisPage.i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) { + return thisPage.i18nText[thisPage.$store.state.i18n.mylang] || '' + } + if (typeof i18nText === 'string'){ + return i18nText } return '' },