feat: add statements and phrase mode for i18n-extend plugin; 🌟

新增:i18n-extend 插件增加语句模式和词组模式;
master
iczer 5 years ago
parent fa3fa22f3c
commit 2cb54136b5
  1. 4
      src/pages/form/advancedForm/i18n-repository.js
  2. 4
      src/pages/form/advancedForm/i18n-task.js
  3. 19
      src/plugins/i18n-extend.js

@ -21,8 +21,8 @@ module.exports = {
type: '倉庫類型', type: '倉庫類型',
}, },
US: { US: {
input: 'Please enter ', input: 'Please enter',
select: 'Please select ', select: 'Please select',
name: 'Repository Name', name: 'Repository Name',
domain: 'Repository Domain', domain: 'Repository Domain',
manager: 'Repository Manager', manager: 'Repository Manager',

@ -21,8 +21,8 @@ module.exports = {
type: '任務類型', type: '任務類型',
}, },
US: { US: {
input: 'Please enter ', input: 'Please enter',
select: 'Please select ', select: 'Please select',
name: 'Task Name', name: 'Task Name',
describe: 'Task Describe', describe: 'Task Describe',
executor: 'Executor', executor: 'Executor',

@ -1,15 +1,26 @@
// 语句模式
const MODE = {
STATEMENTS: 's', //语句模式
PHRASAL: 'p', //词组模式
}
const VueI18nPlugin = { const VueI18nPlugin = {
install: function (Vue) { install: function (Vue) {
Vue.mixin({ Vue.mixin({
methods: { methods: {
$ta(syntaxKey) { $ta(syntaxKey, mode) {
let _mode = mode || MODE.STATEMENTS
let keys = syntaxKey.split('|') let keys = syntaxKey.split('|')
let message = ''
let _this = this let _this = this
let locale = this.$i18n.locale
let message = ''
let splitter = locale == 'US' ? ' ' : ''
// 拼接 message
keys.forEach(key => { keys.forEach(key => {
message += _this.$t(key) message += _this.$t(key) + splitter
}) })
if (keys.length > 0) { // 英文环境语句模式下,转换单词大小写
if (keys.length > 0 && _mode == MODE.STATEMENTS && locale == 'US') {
message = message.charAt(0).toUpperCase() + message.toLowerCase().substring(1) message = message.charAt(0).toUpperCase() + message.toLowerCase().substring(1)
} }
return message return message

Loading…
Cancel
Save