diff --git a/src/core/helpers/i18n/en.json b/src/core/helpers/i18n/en.json index 7bd1e99a14e4ff8798ba365eb1dc9e8d00821c06..46796e5500b15f50a12bb00bef88358fe1c4a04a 100644 --- a/src/core/helpers/i18n/en.json +++ b/src/core/helpers/i18n/en.json @@ -4,6 +4,8 @@ "uni.showLoading.unpaired": "Please note showLoading must be paired with hideLoading", "uni.showModal.cancel": "cancel", "uni.showModal.confirm": "confirm", + "uni.picker.done": "Done", + "uni.picker.cancel": "Cancel", "uni.button.feedback.title": "feedback", "uni.button.feedback.send": "send" -} +} diff --git a/src/core/helpers/i18n/es.json b/src/core/helpers/i18n/es.json index d1d5cd68b338f0ab2cd875e6ad496ce572dd6560..bf63c99235ab43667314a0980061e48be2d89bbb 100644 --- a/src/core/helpers/i18n/es.json +++ b/src/core/helpers/i18n/es.json @@ -3,7 +3,9 @@ "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.showModal.confirm": "confirmar", + "uni.picker.done": "OK", + "uni.picker.cancel": "Cancelar", + "uni.button.feedback.title": "realimentación", "uni.button.feedback.send": "enviar" -} +} diff --git a/src/core/helpers/i18n/fr.json b/src/core/helpers/i18n/fr.json index bcd94c29140473a080536c4e766d3cd5fd834220..ed59dbba5286b2ff4449f44810d87fc473b38db7 100644 --- a/src/core/helpers/i18n/fr.json +++ b/src/core/helpers/i18n/fr.json @@ -4,6 +4,8 @@ "uni.showLoading.unpaired": "Veuillez noter que showLoading doit être associé à hideLoading", "uni.showModal.cancel": "Annuler", "uni.showModal.confirm": "confirmer", + "uni.picker.done": "OK", + "uni.picker.cancel": "Annuler", "uni.button.feedback.title": "retour d'information", "uni.button.feedback.send": "envoyer" -} +} diff --git a/src/core/helpers/i18n/index.js b/src/core/helpers/i18n/index.js index d047d28c08e4a640e4d5fda412e22a22f0b76398..041deccc90a4cb679209b623cee1e6164be90877 100644 --- a/src/core/helpers/i18n/index.js +++ b/src/core/helpers/i18n/index.js @@ -21,4 +21,5 @@ const fallbackLocale = 'en' const i18n = initVueI18n(__PLATFORM__ === 'app-plus' || __PLATFORM__ === 'h5' ? messages : {}, fallbackLocale) export const t = i18n.t export const i18nMixin = i18n.mixin -export const setLocale = i18n.setLocale +export const setLocale = i18n.setLocale +export const getLocale = i18n.getLocale diff --git a/src/core/helpers/i18n/zh-Hans.json b/src/core/helpers/i18n/zh-Hans.json index 678b4378dd0d46f4fdaac73a650621f0ed6dedb7..002e2f274d01f3b0b177cabc2a301a3ba0728da5 100644 --- a/src/core/helpers/i18n/zh-Hans.json +++ b/src/core/helpers/i18n/zh-Hans.json @@ -4,6 +4,8 @@ "uni.showLoading.unpaired": "请注意 showLoading 与 hideLoading 必须配对使用", "uni.showModal.cancel": "取消", "uni.showModal.confirm": "确认", + "uni.picker.done": "完成", + "uni.picker.cancel": "取消", "uni.button.feedback.title": "问题反馈", "uni.button.feedback.send": "发送" -} +} diff --git a/src/core/helpers/i18n/zh-Hant.json b/src/core/helpers/i18n/zh-Hant.json index dd20a4233ebd04f7ffe7c11c095c314ea7274922..b60c33fa8df5ae09c14100fb7d44206a1c8c72bc 100644 --- a/src/core/helpers/i18n/zh-Hant.json +++ b/src/core/helpers/i18n/zh-Hant.json @@ -4,6 +4,8 @@ "uni.showLoading.unpaired": "請注意 showLoading 與 hideLoading 必須配對使用", "uni.showModal.cancel": "取消", "uni.showModal.confirm": "確認", + "uni.picker.done": "完成", + "uni.picker.cancel": "取消", "uni.button.feedback.title": "問題反饋", "uni.button.feedback.send": "發送" -} +} diff --git a/src/platforms/h5/view/components/picker/index.vue b/src/platforms/h5/view/components/picker/index.vue index ac890855bc91a5eb76895431abb68f5a4b7f231b..05e50f4e3fa1f1f34dbb2bce6c8f15ff1352a580 100644 --- a/src/platforms/h5/view/components/picker/index.vue +++ b/src/platforms/h5/view/components/picker/index.vue @@ -33,22 +33,23 @@ class="uni-picker-action uni-picker-action-cancel" @click="_cancel" > - 取消 + {{ $$t("uni.picker.cancel") }}
- 确定 + {{ $$t("uni.picker.done") }}
- {{ typeof item === "object" ? item[rangeKey] || "" : item - }}{{ units[index0] || "" }} + {{ typeof item === "object" ? item[rangeKey] || "" : _l10nItem(item, index0) }}
@@ -115,6 +115,10 @@ import { emitter } from 'uni-mixins' import { formatDateTime } from 'uni-shared' import popup from '../../../components/app/popup/mixins/popup' import keypress from '../../../helpers/keypress' +import { + i18nMixin, + getLocale +} from 'uni-core/helpers/i18n' function getDefaultStartValue () { if (this.mode === mode.TIME) { @@ -172,7 +176,7 @@ const selectorType = { export default { name: 'Picker', components: { keypress }, - mixins: [emitter, popup], + mixins: [i18nMixin, emitter, popup], props: { name: { type: String, @@ -264,16 +268,6 @@ export default { endArray () { return this._getDateValueArray(this.end, getDefaultEndValue.bind(this)()) }, - units () { - switch (this.mode) { - case mode.DATE: - return ['年', '月', '日'] - case mode.TIME: - return ['时', '分'] - default: - return [] - } - }, selectorTypeComputed () { const type = this.selectorType if (Object.values(selectorType).includes(type)) { @@ -610,6 +604,50 @@ export default { style.left = `${$event.clientX - rect.left - fontSize * 1.5}px` style.top = `${$event.clientY - rect.top - fontSize * 0.5}px` } + }, + _pickerViewChange (event) { + this.valueArray == this._l10nColumn(event.detail.value, true) + }, + _l10nColumn (array, normalize) { + if (this.mode === mode.DATE) { + const local = getLocale() + if (!local.startsWith('zh')) { + switch (local) { + case 'es': + case 'fr': + return [array[2], array[1], array[0]] + // case 'en': + default: + return normalize ? [array[2], array[0], array[1]] : [array[1], array[2], array[0]] + } + } + } + return array + }, + _l10nItem (item, index) { + if (this.mode === mode.DATE) { + const local = getLocale() + if (local.startsWith('zh')) { + const array = ['年', '月', '日'] + return item + array[index] + } else if (index === (local === 'es' || local === 'fr' ? 1 : 0)) { + let array + switch (local) { + case 'es': + array = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', '​​julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'] + break + case 'fr': + array = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'] + break + // case 'en': + default: + array = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] + break + } + return array[Number(item) - 1] + } + } + return item } } }