@ohu-mobile/core
Version:
44 lines (43 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _zh_CN = _interopRequireDefault(require("./zh_CN"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var defaultLang = 'zh_CN';
var proto;
var langVar = '$ohuLang';
var messagesVar = '$ohuMessages';
var locale = {
name: 'locale',
installed: false,
install: function install(Vue) {
if (this.installed) return;
var prototype = Vue.prototype,
util = Vue.util;
proto = prototype;
if (util) {
// @ts-ignore
util.defineReactive(prototype, langVar, defaultLang);
}
prototype[messagesVar] = _defineProperty({}, defaultLang, _zh_CN.default);
this.installed = true;
},
use: function use(lang, messages) {
if (proto) {
var msgs = proto[messagesVar];
var hasLang = (lang in msgs);
if (!messages && !hasLang) return;
if (!hasLang && messages) {
msgs[lang] = messages;
}
proto[langVar] = lang;
}
}
};
var _default = exports.default = locale;