From 0e642821eb38850850e037de9a2e6f6d7b8e43ea Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 24 Jan 2021 01:09:01 +0800 Subject: [PATCH] replace i18n filter --- package-lock.json | 5 ----- package.json | 1 - src/filters/localized.js | 3 +++ src/mobile-main.js | 4 ++-- src/views/mobile/Home.vue | 2 +- src/views/mobile/Signup.vue | 2 +- src/views/mobile/accounts/Edit.vue | 4 ++-- src/views/mobile/categories/Preset.vue | 2 +- src/views/mobile/transactions/List.vue | 10 +++++----- src/views/mobile/users/SessionList.vue | 4 ++-- third-patry-licenses.json | 6 ------ 11 files changed, 17 insertions(+), 26 deletions(-) create mode 100644 src/filters/localized.js diff --git a/package-lock.json b/package-lock.json index 16002f90..66e57874 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11163,11 +11163,6 @@ "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-8.22.1.tgz", "integrity": "sha512-JNgiEJ5a8YPfk5y2lKyfOAGLmkpAVfhaUi+T4wGpSppRYZ3XSyawSDDketY5KV2CsAiBLAGEIO6jO+0l2hQubg==" }, - "vue-i18n-filter": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/vue-i18n-filter/-/vue-i18n-filter-0.1.6.tgz", - "integrity": "sha512-zYo06SmMZtJwTkEd2l+t1jCH8lrtTbkwwoz/6XLvFzNF4tGd5CPOhfIxLLv0wf9vxMVYE14KRuzOZzw26qfRxA==" - }, "vue-loader": { "version": "15.9.3", "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.3.tgz", diff --git a/package.json b/package.json index 29166946..2b8f7bd7 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "vue-clipboard2": "^0.3.1", "vue-echarts": "^5.0.0-beta.0", "vue-i18n": "^8.22.1", - "vue-i18n-filter": "^0.1.6", "vue-moment": "^4.1.0", "vue-pincode-input": "^0.4.0", "vuex": "^3.6.0" diff --git a/src/filters/localized.js b/src/filters/localized.js new file mode 100644 index 00000000..bba1f1bc --- /dev/null +++ b/src/filters/localized.js @@ -0,0 +1,3 @@ +export default function ({i18n}, text, options) { + return i18n.t(text, options || {}); +} diff --git a/src/mobile-main.js b/src/mobile-main.js index 9d02b7ac..aaaacb37 100644 --- a/src/mobile-main.js +++ b/src/mobile-main.js @@ -2,7 +2,6 @@ import Vue from 'vue'; import Vuex from 'vuex'; import VueI18n from 'vue-i18n'; -import VueI18nFilter from 'vue-i18n-filter'; import ECharts from 'vue-echarts'; import PincodeInput from 'vue-pincode-input'; import VueMoment from 'vue-moment'; @@ -72,6 +71,7 @@ import userstate from './lib/userstate.js'; import webauthn from './lib/webauthn.js'; import utils from './lib/utils.js'; import stores from './store/index.js'; +import localizedFilter from './filters/localized.js'; import itemFieldContentFilter from './filters/itemFieldContent.js'; import currencyFilter from './filters/currency.js'; import iconFilter from './filters/icon.js'; @@ -129,7 +129,6 @@ Framework7.use(Framework7Vue); Vue.use(Vuex); Vue.use(VueI18n); -Vue.use(VueI18nFilter); Vue.use(VueMoment, { moment }); Vue.use(VueClipboard); @@ -287,6 +286,7 @@ Vue.prototype.$hideLoading = function () { Vue.prototype.$user = userstate; +Vue.filter('localized', (value, options) => localizedFilter({ i18n }, value, options)); Vue.filter('itemFieldContent', (value, fieldName, defaultValue, translate) => itemFieldContentFilter({ i18n }, value, fieldName, defaultValue, translate)); Vue.filter('currency', (value, currencyCode) => currencyFilter({ i18n }, value, currencyCode)); Vue.filter('icon', (value, iconType) => iconFilter(value, iconType)); diff --git a/src/views/mobile/Home.vue b/src/views/mobile/Home.vue index 2a0d040d..bb07dc30 100644 --- a/src/views/mobile/Home.vue +++ b/src/views/mobile/Home.vue @@ -13,7 +13,7 @@ Expense - {{ dateRange.thisMonth.startTime | moment('MMMM') | monthNameLocalizedKey | t }} + {{ dateRange.thisMonth.startTime | moment('MMMM') | monthNameLocalizedKey | localized }} ยท {{ $t('Expense') }} diff --git a/src/views/mobile/Signup.vue b/src/views/mobile/Signup.vue index b9fce343..492a6a4e 100644 --- a/src/views/mobile/Signup.vue +++ b/src/views/mobile/Signup.vue @@ -117,7 +117,7 @@ - {{ categoryType | categoryTypeName($constants.category.allCategoryTypes) | t }} + {{ categoryType | categoryTypeName($constants.category.allCategoryTypes) | localized }} diff --git a/src/views/mobile/accounts/Edit.vue b/src/views/mobile/accounts/Edit.vue index 41e09ef5..68e30ef5 100644 --- a/src/views/mobile/accounts/Edit.vue +++ b/src/views/mobile/accounts/Edit.vue @@ -24,7 +24,7 @@ - {{ categoryInfo.type | categoryTypeName($constants.category.allCategoryTypes) | t }} + {{ categoryInfo.type | categoryTypeName($constants.category.allCategoryTypes) | localized }} diff --git a/src/views/mobile/transactions/List.vue b/src/views/mobile/transactions/List.vue index cbd2ba98..8b63adea 100644 --- a/src/views/mobile/transactions/List.vue +++ b/src/views/mobile/transactions/List.vue @@ -26,10 +26,10 @@ - {{ query.dateType | dateRangeName(allDateRanges, 'Date') | t }} + {{ query.dateType | dateRangeName(allDateRanges, 'Date') | localized }} - {{ query.type | typeName('Type') | t }} + {{ query.type | typeName('Type') | localized }} {{ query.categoryId | categoryName(allCategories, $t('Category')) }} @@ -165,7 +165,7 @@ {{ transaction.day }} - {{ `datetime.${transaction.dayOfWeek}.short` | t }} + {{ `datetime.${transaction.dayOfWeek}.short` | localized }}
@@ -186,7 +186,7 @@ {{ transaction.category.name }} - {{ transaction.type | transactionTypeName($constants.transaction.allTransactionTypes) | t }} + {{ transaction.type | transactionTypeName($constants.transaction.allTransactionTypes) | localized }}
@@ -233,7 +233,7 @@
+ :title="token | tokenTitle | localized" + :text="token | tokenDevice | localized"> {{ token.createdAt | moment($t('format.datetime.long')) }} diff --git a/third-patry-licenses.json b/third-patry-licenses.json index 62ec4107..89cc681b 100644 --- a/third-patry-licenses.json +++ b/third-patry-licenses.json @@ -99,12 +99,6 @@ "url": "https://github.com/kazupon/vue-i18n", "licenseUrl": "https://github.com/kazupon/vue-i18n/blob/v8.x/LICENSE" }, - { - "name": "vue-i18n-filter", - "copyright": "Copyright (c) 2018 +v", - "url": "https://github.com/chiaweilee/vue-i18n-filter", - "licenseUrl": "https://github.com/chiaweilee/vue-i18n-filter/blob/master/LICENSE" - }, { "name": "vue-moment", "copyright": "Copyright (c) 2017 Brock Petrie",