{"version":3,"file":"discourse-translator.js","names":["define","_exports","_component","_decorators","_dec","_obj","Object","defineProperty","value","default","target","property","decorators","descriptor","context","desc","extend","loading","translated_text","getOwnPropertyDescriptor","keys","forEach","key","enumerable","configurable","initializer","writable","slice","reverse","reduce","decorator","call","undefined","_ajax","_ajaxError","_pluginApi","_I18n","initializeTranslation","api","siteSettings","container","lookup","getCurrentUser","translator_enabled","includePostAttributes","decorateWidget","dec","state","isTranslated","isTranslating","h","language","attrs","detected_lang","translator","titleElements","translated_title","t","cooked","attachWidgetAction","this","scheduleRerender","post","findAncestorModel","ajax","type","data","post_id","get","then","res","setProperties","translation","title_translation","translatePost","catch","error","popupAjaxError","finally","set","addPostMenuButton","can_translate","action","title","icon","position","className","name","initialize","withPluginApi","_deprecationsHelper","_templateFactory","createTemplateFactory","id","block","moduleName","scope","isStrictMode"],"sources":["discourse/plugins/discourse-translator/discourse/components/translated-post.js","discourse/plugins/discourse-translator/discourse/initializers/extend-for-translate-button.js","discourse/plugins/discourse-translator/discourse/templates/components/translated-post.js","discourse/plugins/discourse-translator/discourse/templates/connectors/post-after-cooked/translate.js"],"sourcesContent":["define(\"discourse/plugins/discourse-translator/discourse/components/translated-post\", [\"exports\", \"@ember/component\", \"discourse-common/utils/decorators\"], function (_exports, _component, _decorators) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  var _dec, _obj;\n  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }\n  var _default = _exports.default = _component.default.extend((_dec = (0, _decorators.default)(\"post.translated_text\"), (_obj = {\n    loading(translated_text) {\n      return translated_text === true ? true : false;\n    }\n  }, (_applyDecoratedDescriptor(_obj, \"loading\", [_dec], Object.getOwnPropertyDescriptor(_obj, \"loading\"), _obj)), _obj)));\n});","define(\"discourse/plugins/discourse-translator/discourse/initializers/extend-for-translate-button\", [\"exports\", \"discourse/lib/ajax\", \"discourse/lib/ajax-error\", \"discourse/lib/plugin-api\", \"I18n\"], function (_exports, _ajax, _ajaxError, _pluginApi, _I18n) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  function translatePost(post) {\n    return (0, _ajax.ajax)(\"/translator/translate\", {\n      type: \"POST\",\n      data: {\n        post_id: post.get(\"id\")\n      }\n    }).then(function (res) {\n      post.setProperties({\n        translated_text: res.translation,\n        detected_lang: res.detected_lang,\n        translated_title: res.title_translation\n      });\n    });\n  }\n  function initializeTranslation(api) {\n    const siteSettings = api.container.lookup(\"service:site-settings\");\n    const currentUser = api.getCurrentUser();\n    if (!currentUser) {\n      return;\n    }\n    if (!siteSettings.translator_enabled) {\n      return;\n    }\n    api.includePostAttributes(\"can_translate\", \"translated_text\", \"detected_lang\", \"translated_title\");\n    api.decorateWidget(\"post-menu:before\", dec => {\n      if (!dec.state.isTranslated) {\n        return;\n      }\n      if (dec.state.isTranslating) {\n        return dec.h(\"div.spinner.small\");\n      }\n      const language = dec.attrs.detected_lang;\n      const translator = siteSettings.translator;\n      let titleElements = [];\n      if (dec.attrs.translated_title) {\n        titleElements = [dec.h(\"div.topic-attribution\", dec.attrs.translated_title)];\n      }\n      return dec.h(\"div.post-translation\", [dec.h(\"hr\"), ...titleElements, dec.h(\"div.post-attribution\", _I18n.default.t(\"translator.translated_from\", {\n        language,\n        translator\n      })), dec.cooked(dec.attrs.translated_text)]);\n    });\n    api.attachWidgetAction(\"post-menu\", \"translate\", function () {\n      const state = this.state;\n      state.isTranslated = true;\n      state.isTranslating = true;\n      this.scheduleRerender();\n      const post = this.findAncestorModel();\n      if (post) {\n        return translatePost(post).catch(error => {\n          (0, _ajaxError.popupAjaxError)(error);\n          state.isTranslating = false;\n          state.isTranslated = false;\n        }).finally(() => state.isTranslating = false);\n      }\n    });\n    api.attachWidgetAction(\"post-menu\", \"hideTranslation\", function () {\n      this.state.isTranslated = false;\n      const post = this.findAncestorModel();\n      if (post) {\n        post.set(\"translated_text\", \"\");\n      }\n    });\n    api.addPostMenuButton(\"translate\", (attrs, state) => {\n      if (!attrs.can_translate) {\n        return;\n      }\n      const [action, title] = !state.isTranslated ? [\"translate\", \"translator.view_translation\"] : [\"hideTranslation\", \"translator.hide_translation\"];\n      return {\n        action,\n        title,\n        icon: \"globe\",\n        position: \"first\",\n        className: state.isTranslated ? \"translated\" : null\n      };\n    });\n  }\n  var _default = _exports.default = {\n    name: \"extend-for-translate-button\",\n    initialize() {\n      (0, _pluginApi.withPluginApi)(\"0.1\", api => initializeTranslation(api));\n    }\n  };\n});","define(\"discourse/plugins/discourse-translator/discourse/templates/components/translated-post\", [\"exports\", \"ember-this-fallback/deprecations-helper\", \"@ember/template-factory\"], function (_exports, _deprecationsHelper, _templateFactory) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  var _default = _exports.default = (0, _templateFactory.createTemplateFactory)(\n  /*\n    {{#if post.translated_text}}\n    <ConditionalLoadingSpinner @condition={{loading}} @size=\"small\">\n      <div class=\"post-translation\">\n        <hr />\n  \n        <div class=\"post-attribution\">\n          {{i18n\n            \"translator.translated_from\"\n            language=post.detected_lang\n            translator=siteSettings.translator\n          }}\n        </div>\n  \n        {{html-safe post.translated_text}}\n      </div>\n    </ConditionalLoadingSpinner>\n  {{/if}}\n  */\n  {\n    \"id\": \"LwEL0jxU\",\n    \"block\": \"[[[41,[30,0,[\\\"post\\\",\\\"translated_text\\\"]],[[[1,\\\"  \\\"],[8,[39,1],null,[[\\\"@condition\\\",\\\"@size\\\"],[[30,0,[\\\"loading\\\"]],\\\"small\\\"]],[[\\\"default\\\"],[[[[1,\\\"\\\\n    \\\"],[10,0],[14,0,\\\"post-translation\\\"],[12],[1,\\\"\\\\n      \\\"],[10,\\\"hr\\\"],[12],[13],[1,\\\"\\\\n\\\\n      \\\"],[10,0],[14,0,\\\"post-attribution\\\"],[12],[1,\\\"\\\\n        \\\"],[1,[28,[35,2],[\\\"translator.translated_from\\\"],[[\\\"language\\\",\\\"translator\\\"],[[30,0,[\\\"post\\\",\\\"detected_lang\\\"]],[30,0,[\\\"siteSettings\\\",\\\"translator\\\"]]]]]],[1,\\\"\\\\n      \\\"],[13],[1,\\\"\\\\n\\\\n      \\\"],[1,[28,[35,3],[[30,0,[\\\"post\\\",\\\"translated_text\\\"]]],null]],[1,\\\"\\\\n    \\\"],[13],[1,\\\"\\\\n  \\\"]],[]]]]],[1,\\\"\\\\n\\\"]],[]],null],[1,[28,[32,0],[\\\"[[\\\\\\\"The `post` property path was used in the `discourse/plugins/discourse-translator/discourse/templates/components/translated-post.hbs` template without using `this`. This fallback behavior has been deprecated, all properties must be looked up on `this` when used in the template: {{this.post}}\\\\\\\",false,{\\\\\\\"id\\\\\\\":\\\\\\\"ember-this-fallback.this-property-fallback\\\\\\\",\\\\\\\"until\\\\\\\":\\\\\\\"n/a\\\\\\\",\\\\\\\"for\\\\\\\":\\\\\\\"ember-this-fallback\\\\\\\",\\\\\\\"url\\\\\\\":\\\\\\\"https://deprecations.emberjs.com/v3.x#toc_this-property-fallback\\\\\\\",\\\\\\\"since\\\\\\\":{\\\\\\\"available\\\\\\\":\\\\\\\"0.2.0\\\\\\\"}}],[\\\\\\\"The `loading` property path was used in the `discourse/plugins/discourse-translator/discourse/templates/components/translated-post.hbs` template without using `this`. This fallback behavior has been deprecated, all properties must be looked up on `this` when used in the template: {{this.loading}}\\\\\\\",false,{\\\\\\\"id\\\\\\\":\\\\\\\"ember-this-fallback.this-property-fallback\\\\\\\",\\\\\\\"until\\\\\\\":\\\\\\\"n/a\\\\\\\",\\\\\\\"for\\\\\\\":\\\\\\\"ember-this-fallback\\\\\\\",\\\\\\\"url\\\\\\\":\\\\\\\"https://deprecations.emberjs.com/v3.x#toc_this-property-fallback\\\\\\\",\\\\\\\"since\\\\\\\":{\\\\\\\"available\\\\\\\":\\\\\\\"0.2.0\\\\\\\"}}],[\\\\\\\"The `post` property path was used in the `discourse/plugins/discourse-translator/discourse/templates/components/translated-post.hbs` template without using `this`. This fallback behavior has been deprecated, all properties must be looked up on `this` when used in the template: {{this.post}}\\\\\\\",false,{\\\\\\\"id\\\\\\\":\\\\\\\"ember-this-fallback.this-property-fallback\\\\\\\",\\\\\\\"until\\\\\\\":\\\\\\\"n/a\\\\\\\",\\\\\\\"for\\\\\\\":\\\\\\\"ember-this-fallback\\\\\\\",\\\\\\\"url\\\\\\\":\\\\\\\"https://deprecations.emberjs.com/v3.x#toc_this-property-fallback\\\\\\\",\\\\\\\"since\\\\\\\":{\\\\\\\"available\\\\\\\":\\\\\\\"0.2.0\\\\\\\"}}],[\\\\\\\"The `siteSettings` property path was used in the `discourse/plugins/discourse-translator/discourse/templates/components/translated-post.hbs` template without using `this`. This fallback behavior has been deprecated, all properties must be looked up on `this` when used in the template: {{this.siteSettings}}\\\\\\\",false,{\\\\\\\"id\\\\\\\":\\\\\\\"ember-this-fallback.this-property-fallback\\\\\\\",\\\\\\\"until\\\\\\\":\\\\\\\"n/a\\\\\\\",\\\\\\\"for\\\\\\\":\\\\\\\"ember-this-fallback\\\\\\\",\\\\\\\"url\\\\\\\":\\\\\\\"https://deprecations.emberjs.com/v3.x#toc_this-property-fallback\\\\\\\",\\\\\\\"since\\\\\\\":{\\\\\\\"available\\\\\\\":\\\\\\\"0.2.0\\\\\\\"}}],[\\\\\\\"The `post` property path was used in the `discourse/plugins/discourse-translator/discourse/templates/components/translated-post.hbs` template without using `this`. This fallback behavior has been deprecated, all properties must be looked up on `this` when used in the template: {{this.post}}\\\\\\\",false,{\\\\\\\"id\\\\\\\":\\\\\\\"ember-this-fallback.this-property-fallback\\\\\\\",\\\\\\\"until\\\\\\\":\\\\\\\"n/a\\\\\\\",\\\\\\\"for\\\\\\\":\\\\\\\"ember-this-fallback\\\\\\\",\\\\\\\"url\\\\\\\":\\\\\\\"https://deprecations.emberjs.com/v3.x#toc_this-property-fallback\\\\\\\",\\\\\\\"since\\\\\\\":{\\\\\\\"available\\\\\\\":\\\\\\\"0.2.0\\\\\\\"}}]]\\\"],null]]],[],false,[\\\"if\\\",\\\"conditional-loading-spinner\\\",\\\"i18n\\\",\\\"html-safe\\\"]]\",\n    \"moduleName\": \"discourse/plugins/discourse-translator/discourse/templates/components/translated-post.hbs\",\n    \"scope\": () => [_deprecationsHelper.default],\n    \"isStrictMode\": false\n  });\n});","define(\"discourse/plugins/discourse-translator/discourse/templates/connectors/post-after-cooked/translate\", [\"exports\", \"@ember/template-factory\"], function (_exports, _templateFactory) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  var _default = _exports.default = (0, _templateFactory.createTemplateFactory)(\n  /*\n    <TranslatedPost @post={{this}} />\n  */\n  {\n    \"id\": \"YWQDAaKk\",\n    \"block\": \"[[[8,[39,0],null,[[\\\"@post\\\"],[[30,0]]],null]],[],false,[\\\"translated-post\\\"]]\",\n    \"moduleName\": \"discourse/plugins/discourse-translator/discourse/templates/connectors/post-after-cooked/translate.hbs\",\n    \"isStrictMode\": false\n  });\n});"],"mappings":"AAAAA,OAAA,2JAAAC,EAAAC,EAAAC,GACA;AAMA,IAAAC,EAAAC;AAJAC,OAAAC,eAAAN,EAAA,cACAO,OAAA,IAEAP,EAAAQ,aAAA;AAGA,IADAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC;AACAd,EAAAQ,QAAAP,EAAAO,QAAAO,QAAAZ,GAAA,EAAAD,EAAAM,SAAA,wBADAC,EACAL,EAAA,CACAY,QA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