vant/packages/mixins/i18n.js
2018-12-14 14:24:23 +08:00

25 lines
662 B
JavaScript

// component mixin
import { get, camelize } from '../utils';
export default {
computed: {
$t() {
const { name } = this.$options;
const prefix = name ? camelize(name) + '.' : '';
if (!this.$vantMessages) {
if (process.env.NODE_ENV !== 'production') {
console.error('[Vant] Locale not correctly registered');
}
return () => '';
}
const messages = this.$vantMessages[this.$vantLang];
return (path, ...args) => {
const message = get(messages, prefix + path) || get(messages, path);
return typeof message === 'function' ? message(...args) : message;
};
}
}
};