vue-i18n-phrase-in-context-editor
Version:
Integrate Phrase In-Context Editor into your Vue I18n app with ease!
217 lines (197 loc) • 7.22 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["vue-i18n-phrase-in-context-editor"] = factory();
else
root["vue-i18n-phrase-in-context-editor"] = factory();
})((typeof self !== 'undefined' ? self : this), function() {
return /******/ (function() { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 231:
/***/ (function() {
(function() {
/* istanbul ignore next */
if (typeof globalThis === 'object') return;
Object.defineProperty(Object.prototype, '__magic__', {
get: function() {
return this;
},
configurable: true, // This makes it possible to `delete` the getter later.
});
__magic__.globalThis = __magic__; // lolwat
delete Object.prototype.__magic__;
})();
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ !function() {
/******/ __webpack_require__.p = "";
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
!function() {
;
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
VueI18nPhraseFormatter: function() { return /* reexport */ VueI18nPhraseFormatter; },
"default": function() { return /* binding */ entry_lib; }
});
;// ./node_modules/.pnpm/@vue+cli-service@5.0.9_esbuild@0.14.7_vue-template-compiler@2.6.11_vue@2.6.11/node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
/* eslint-disable no-var */
// This file is imported into lib/wc client bundles.
if (typeof window !== 'undefined') {
var currentScript = window.document.currentScript
if (false) // removed by dead control flow
{ var getCurrentScript; }
var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
if (src) {
__webpack_require__.p = src[1] // eslint-disable-line
}
}
// Indicate to webpack that this file can be concatenated
/* harmony default export */ var setPublicPath = (null);
// EXTERNAL MODULE: ./node_modules/.pnpm/@sagi.io+globalthis@0.0.2/node_modules/@sagi.io/globalthis/index.js
var globalthis = __webpack_require__(231);
;// ./src/vue-i18n-phrase-formatter.ts
class VueI18nPhraseFormatter {
constructor(options) {
this.prefix = options.prefix;
this.suffix = options.suffix;
}
interpolate(message, values, path) {
return [this.prefix, 'phrase_', path, this.suffix];
}
}
;// ./src/vue-i18n-phrase.ts
class VueI18nPhrase {
constructor(vueI18n, options) {
this.vueI18n = vueI18n;
this.config = {
...globalThis.PHRASEAPP_CONFIG,
...options
};
this.phraseEnabled = options.phraseEnabled;
}
loadInContextEditor() {
this.phraseScript = document.createElement('script');
this.phraseScript.async = true;
if (!this.config.useOldICE) {
this.phraseScript.type = 'module';
this.phraseScript.src = `https://cdn.phrase.com/strings/plugins/editor/latest/ice/index.js`;
} else {
this.phraseScript.type = 'text/javascript';
this.phraseScript.src = `https://phrase.com/assets/in-context-editor/2.0/app.js?${new Date().getTime()}`;
}
const script = document.getElementsByTagName('script')[0];
if (script?.parentNode) {
script.parentNode.insertBefore(this.phraseScript, script);
} else {
document.body.appendChild(this.phraseScript);
}
}
set phraseEnabled(phraseEnabled) {
globalThis.PHRASEAPP_ENABLED = phraseEnabled;
if (phraseEnabled) {
if (!this.phraseScript) {
this.loadInContextEditor();
}
this.previousVueI18nFormatter = this.vueI18n.formatter;
this.vueI18n.formatter = new VueI18nPhraseFormatter({
prefix: this.config.prefix,
suffix: this.config.suffix
});
} else if (this.previousVueI18nFormatter) {
this.vueI18n.formatter = this.previousVueI18nFormatter;
}
}
get phraseEnabled() {
return globalThis.PHRASEAPP_ENABLED;
}
set config(options) {
globalThis.PHRASEAPP_CONFIG = {
...VueI18nPhrase.defaultConfig,
...options
};
}
get config() {
return globalThis.PHRASEAPP_CONFIG;
}
}
VueI18nPhrase.defaultConfig = {
prefix: '{{__',
suffix: '__}}',
useOldICE: false,
fullReparse: true,
origin: 'vue-i18n-phrase-in-context-editor'
};
;// ./index.ts
/* harmony default export */ var index = (VueI18nPhrase);
;// ./node_modules/.pnpm/@vue+cli-service@5.0.9_esbuild@0.14.7_vue-template-compiler@2.6.11_vue@2.6.11/node_modules/@vue/cli-service/lib/commands/build/entry-lib.js
/* harmony default export */ var entry_lib = (index);
}();
/******/ return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=vue-i18n-phrase-in-context-editor.umd.js.map