UNPKG

vue-i18n-composable

Version:
36 lines (32 loc) 1.1 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/index.ts var _vue = require('vue'); var _vue2 = _interopRequireDefault(_vue); var _vuei18n = require('vue-i18n'); var _vuei18n2 = _interopRequireDefault(_vuei18n); var i18nInstance; function createI18n(options) { i18nInstance = new (0, _vuei18n2.default)(options); return i18nInstance; } function useI18n() { if (!i18nInstance) throw new Error("vue-i18n not initialized"); const i18n = i18nInstance; const instance = _vue.getCurrentInstance.call(void 0, ); const vm = (instance == null ? void 0 : instance.proxy) || instance || new (0, _vue2.default)({}); const locale = _vue.computed.call(void 0, { get() { return i18n.locale; }, set(v) { i18n.locale = v; } }); return { locale, t: vm.$t.bind(vm), tc: vm.$tc.bind(vm), d: vm.$d.bind(vm), te: vm.$te.bind(vm), n: vm.$n.bind(vm) }; } exports.createI18n = createI18n; exports.useI18n = useI18n;