i18next-phrase-in-context-editor-post-processor
Version:
Plugin for i18next that pairs well with Phrase In-Context Editor
3 lines (2 loc) • 2.01 kB
JavaScript
import"@sagi.io/globalthis";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},t.apply(this,arguments)}class e{get IN_CONTEXT_EDITOR_SCRIPT_URL(){return this.config.useOldICE?`https://phrase.com/assets/in-context-editor/2.0/app.js?${(new Date).getTime()}`:"https://cdn.phrase.com/strings/plugins/editor/latest/ice/index.js"}static interpolateKey(t,e,i){return e+"phrase_"+t+i}loadInContextEditorScript(){if("undefined"!=typeof window){const t=document.createElement("script");t.type=this.config.useOldICE?"text/javascript":"module",t.async=!0,t.src=this.IN_CONTEXT_EDITOR_SCRIPT_URL;const e=document.getElementsByTagName("script")[0];return e&&e.parentNode?e.parentNode.insertBefore(t,e):document.body.appendChild(t),t}}constructor(e){this.defaultConfig={prefix:"{{__",suffix:"__}}",fullReparse:!0,useOldICE:!1,scriptAutoLoad:!0,origin:"i18next-phrase-in-context-editor-post-processor"},this.phraseScript=void 0,this.type="postProcessor",this.name="phraseInContextEditor",this.config=t({},globalThis.PHRASEAPP_CONFIG,e),this.phraseEnabled=e.phraseEnabled}interpolateKey(t){return e.interpolateKey(t,this.config.prefix,this.config.suffix)}process(t,e,i,s){return this.phraseEnabled?this.interpolateKey(e[0]):t}set phraseEnabled(t){globalThis.PHRASEAPP_ENABLED=t,t&&this.config.scriptAutoLoad&&!this.phraseScript&&(this.phraseScript=this.loadInContextEditorScript())}get phraseEnabled(){return globalThis.PHRASEAPP_ENABLED}set config(e){globalThis.PHRASEAPP_CONFIG=t({},this.defaultConfig,e)}get config(){return globalThis.PHRASEAPP_CONFIG}toScriptHTML(){return`<script>window.PHRASEAPP_ENABLED=true;window.PHRASEAPP_CONFIG=${JSON.stringify(this.config)}<\/script><script type="text/javascript" async src="${this.IN_CONTEXT_EDITOR_SCRIPT_URL}"><\/script>`}}export{e as default};
//# sourceMappingURL=i18next-phrase-in-context-editor-post-processor.modern.js.map