text: "use strict";function _typeof(obj){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj}}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj}}return _typeof(obj)}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter((function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable}));keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach((function(key){_defineProperty(target,key,source[key])}))}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach((function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))}))}}return target}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass)}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o};return _setPrototypeOf(o,p)}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget)}else{result=Super.apply(this,arguments)}return _possibleConstructorReturn(this,result)}}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call}return _assertThisInitialized(self)}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Date.prototype.toString.call(Reflect.construct(Date,[],(function(){})));return true}catch(e){return false}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _getPrototypeOf(o)}var crowdin_translation_helper=function(_CrowdinComponent){_inherits(crowdin_translation_helper,_CrowdinComponent);var _super=_createSuper(crowdin_translation_helper);function crowdin_translation_helper(){_classCallCheck(this,crowdin_translation_helper);return _super.apply(this,arguments)}_createClass(crowdin_translation_helper,[{key:"prepareText",value:function prepareText(translation,leave_phrase_terms){if(!crowdin.phrases||translation.text===undefined||!translation.id&&!crowdin.translation){return""}var translationObj=_objectSpread({},translation);var translation_id=translation.id||crowdin.translation.translation_id;var markup_replacer=crowdin.phrases.markup_replacer(translation_id);translationObj.text=markup_replacer.mask(translationObj.text,true);if(!translationObj.hasOwnProperty("is_icu")){translationObj.is_icu=crowdin.translation.is_icu}translationObj.text=this.lightIcu(translationObj.text,translationObj.is_icu);var text=translationObj.text;if(crowdin.glossary&&text){try{text=crowdin.glossary.mask_terms(crowdin.glossary.parse(translationObj,leave_phrase_terms))}catch(e){console.warn("Can't highlight terms, returning input text.")}}var alignments=crowdin.helpers.alignment.get(translation_id);if(alignments&&Object.keys(alignments).length>0){text=crowdin.highlight.mask(text);text=crowdin.helpers.alignment.parseAlignments(text,alignments);crowdin.helpers.alignment.parseAlignmentsOnMaskedTerms(alignments);text=crowdin.highlight.unmask(text);text=crowdin.helpers.alignment.mask_alignment(text)}text=crowdin.highlight.light(text,markup_replacer.tags);text=crowdin.helpers.alignment.unmask_alignment(text);text=crowdin.glossary.unmask_terms(text);this.addTextareaHighlightMapping(translation,translationObj.is_icu);crowdin.highlight.mapping=[];return text}},{key:"addTextareaHighlightMapping",value:function addTextareaHighlightMapping(translation,isIcu){if(isIcu){crowdin.translation.textarea_highlight.refreshIcuLight(translation)}else{var highlightMapping=_.uniqWith(crowdin.highlight.mapping,_.isEqual);crowdin.translation.textarea_highlight.addToMapping(translation.id,highlightMapping)}}},{key:"lightIcu",value:function lightIcu(text,is_icu){is_icu=is_icu||crowdin.translation.is_icu;text=text.replace(/\u2028/g,"\n");if(is_icu){var mfl=new MessageFormatLight(crowdin.editor.source_language.code);var ast=mfl.isIcuFormat(text)||[];if(typeof crowdin.translation.icu_params!=="undefined"){crowdin.translation.icu_params.source=ast}text=crowdin.highlight.light_icu(text,ast)}return text}},{key:"prepareContext",value:function prepareContext(context){context=nl2br(context);context=context.replace(/(style\s*=\s*(&#039;|&#34;|'|&quot;)(.*)(&#039;|&#34;|'|&quot;))/gim,"");context=context.replace(/(&lt;a\s.*?&gt;)(.*?)&lt;\/a&gt;/gi,(function($0,$1,$2){return htmlspecialchars_decode($1)+$2+"</a>"}));context=sanitizer.attributes(context);context=context.replace(/(^|[^\/\/])(www\.([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?)/gim,(function($0,$1,$2){return $1+'<a href="http://'+$2+'">'+$2+"</a>"}));var email_pattern=/((mailto\:\/\/)|(<a href=("|'))|(<a(.*)href=("|')))?([\w\-_0-9]+@([\w\-_0-9]+\.)*([\w\-_0-9]+)?(\.[a-zA-Z]{2,6})+)/gi;context=context.replace(email_pattern,(function($0,$1){return $1?$0:'<a href="mailto://'+$0+'">'+$0+"</a>"}));var url_pattern=/((<a href=("|'))|(<a(.*)href=("|')))?(((http|ftp|https):\/\/)[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?((\([\w+\-]*\))*([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?)*)/gi;context=context.replace(url_pattern,(function($0,$1){return $1?$0:'<a href="'+$0+'">'+$0+"</a>"}));var mailto_pattern=/((<a href=("|'))|(<a(.*)href=("|')))?(((mailto:\/\/[\w\-_0-9]+@[\w\-_0-9]+\.[\w]+))|(([a-zA-Z0-9\-\_\.]))+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gi;context=context.replace(mailto_pattern,(function($0,$1){return $1?$0:'<a href="mailto://'+$0+'">'+$0+"</a>"}));context=context.replace(/(mailto:\/\/mailto:\/\/)/gi,"mailto://");context=context.replace(/<a ([^>]+)>/gi,'<a target="_blank" rel="noreferrer nofollow" $1>');context=context.replace(/HTTP-EQUIV=(?:'([^\s>]*)'|"([^\s>]*)")/gi,"HTTP-EQUIV='#'");return context}},{key:"is_whole_word",value:function is_whole_word(phrase,position,length){var leading_char=phrase.charAt(position-1),trailing_char=phrase.charAt(position+length),subString=phrase.substr(position,length),not_alphabetic=!this.is_alphabetic_char(leading_char)&&!this.is_alphabetic_char(trailing_char)||this.is_hieroglyph(subString);return!this.overlap_entity(phrase,position,length)&&not_alphabetic}},{key:"overlap_entity",value:function overlap_entity(phrase,position,length){var match,entityStart,entityEnd,wordStart=position,wordEnd=position+length-1,overlapEntity=false;var firstCapturingGroup="(".concat(crowdin.helpers.alignment.maskBuilder.leftPart(),"|").concat(crowdin.highlight.maskBuilder.leftPart(),"|").concat(crowdin.glossary.maskBuilder.leftPart(),")");var secondCapturingGroup="(".concat(crowdin.helpers.alignment.maskBuilder.rightPart(),"|").concat(crowdin.glossary.maskBuilder.rightPart(),"|").concat(crowdin.highlight.maskBuilder.rightPart(),")");var pattern="".concat(firstCapturingGroup,"\\w+(?:_\\w+)?(?:_true|_false)?").concat(secondCapturingGroup);var regexp=new RegExp(pattern,"g");while((match=regexp.exec(phrase))!=null){entityStart=match.index;entityEnd=match.index+match[0].length-1;var entityConditionsOverlapping=[wordStart>=entityStart&&wordEnd<=entityEnd,wordEnd>=entityStart&&wordEnd<=entityEnd,wordStart<=entityStart&&wordEnd>=entityStart,wordStart<=entityEnd&&wordEnd>=entityEnd];if(in_array(true,entityConditionsOverlapping,false)){overlapEntity=true;break}}return overlapEntity}},{key:"is_alphabetic_char",value:function is_alphabetic_char(_char){var specialchars=/[~`!@#$%^&*(){}\[\];:"'<,.>?\/\\|_+=\-\s\n\r\t\u2000-\u206F\u2E00-\u2E7F]/;return!!(_char&&!_char.match(specialchars))}},{key:"is_hieroglyph",value:function is_hieroglyph(str){return str.match(/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff66-\uffbE\u4e00-\u9faf\u3400-\u4db5\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc]/gi)!==null}},{key:"update_unsaved_suggestions_storage",value:function update_unsaved_suggestions_storage(text,id,plural_identifier){if(!id){return}var plural_id=typeof plural_identifier!=="undefined"?plural_identifier:crowdin.translation.plural_id;var storage=crowdin.suggestions.unsaved_suggestions,key=this.get_storage_suggestions_key(id,plural_id);storage.set(key,crowdin.phrases.markup_replacer().unmask(text))}},{key:"remove_unsaved_suggestions_storage",value:function remove_unsaved_suggestions_storage(id,plural_id){var storage=crowdin.suggestions.unsaved_suggestions,key=this.get_storage_suggestions_key(id,plural_id);storage.remove(key)}},{key:"has_unsaved",value:function has_unsaved(input_text,id,plural_identifier){var text=!input_text?crowdin.translation.get_suggest_text():crowdin.phrases.markup_replacer().unmask(input_text),translation_exist=false;var plural_id=typeof plural_identifier!=="undefined"?plural_identifier:crowdin.translation.plural_id,translation_id=typeof id!=="undefined"?id:crowdin.translation.translation_id;var suggestions=crowdin.suggestions.get_suggestions(translation_id,plural_id);for(var i in suggestions){if(suggestions[i].text===text){translation_exist=true;break}}return text.length>=0&&!translation_exist}},{key:"get_storage_suggestions_key",value:function get_storage_suggestions_key(id,plural_identifer){var plural_id=typeof plural_identifer!=="undefined"?plural_identifer:crowdin.translation.plural_id,has_plurals=plural_id!==-1;return has_plurals?this.get_storage_translation_key(id)+":plural-"+plural_id:this.get_storage_translation_key(id)}},{key:"get_storage_discussions_key",value:function get_storage_discussions_key(id){return this.get_storage_translation_key(id)}},{key:"get_storage_translation_key",value:function get_storage_translation_key(id){if(!id){id=crowdin.translation.translation_id}return[crowdin.user.id,crowdin.editor.project.id,crowdin.editor.target_language.id,id].join(":")}},{key:"update_unsaved_discussions_storage",value:function update_unsaved_discussions_storage(id,discussion){if(!id){return}var storage=crowdin.panel.unsaved_discussions,key=this.get_storage_discussions_key(id);storage.set(key,JSON.stringify(discussion))}},{key:"remove_unsaved_discussions_storage",value:function remove_unsaved_discussions_storage(id){var storage=crowdin.panel.unsaved_discussions,key=this.get_storage_discussions_key(id);storage.remove(key)}},{key:"get_prev_plural_id",value:function get_prev_plural_id(id){var index=crowdin.editor.target_language.plural_ids.indexOf(id);if(index>0){return crowdin.editor.target_language.plural_ids[index-1]}return-1}},{key:"get_next_plural_id",value:function get_next_plural_id(id){var index=crowdin.editor.target_language.plural_ids.indexOf(id);if(index>=0&&index<crowdin.editor.target_language.plural_ids.length-1){return crowdin.editor.target_language.plural_ids[index+1]}return-1}},{key:"inform",value:function inform(message){var options={sticky:false,afterOpen:function afterOpen(){$(".jGrowl-default-buttons","#jGrowl").find("button:first").focus()}};crowdin.notify(message,options)}},{key:"hasOwnSuggestions",value:function hasOwnSuggestions(translation_id,suggestions){for(var plural_id in suggestions){for(var i in suggestions[plural_id]){if(suggestions[plural_id][i].translation_id===translation_id&&typeof suggestions[plural_id][i].deleted==="undefined"||suggestions[plural_id][i].translation_id===translation_id&&suggestions[plural_id][i].deleted===false){return true}}}return false}},{key:"getStringUrlById",value:function getStringUrlById(translationId){if(!translationId){return"#"}return crowdin.helpers.url.buildEditorPath({file_id:"all",options:{hash:translationId}})}},{key:"getStringUrl",value:function getStringUrl(){if(!crowdin.translation.translation_id){return"#"}return crowdin.helpers.url.build("".concat(window.location.origin+this.getFileUrl()),null,crowdin.translation.translation_id)}},{key:"getHistoryUrl",value:function getHistoryUrl(){return crowdin.helpers.url.getActivityUrl()+"&translation_id="+crowdin.translation.translation_id}},{key:"getFileUrl",value:function getFileUrl(){return crowdin.editor.getFileUrl(crowdin.translation.get_translation().file_id)}},{key:"toggle_status",value:function toggle_status(done){var translation_id=crowdin.translation.translation_id;var params=["todo/done",crowdin.editor.project.id,translation_id];if(crowdin.ajax.isLocked(params)){return}var url=done?"/translation/mark_as_done":"/translation/mark_as_to_do";crowdin.models.phrases.edit_translation(translation_id,{step_status:done?STEP_DONE:STEP_TODO});crowdin.ajax.getData(url,{project_id:crowdin.editor.project.id,translation_id:translation_id,workflow_step_id:crowdin.editor.workflow_step.id,target_language_id:crowdin.editor.target_language.id,_lockKey:params},(function(data){if(data.error){crowdin.models.phrases.edit_translation(translation_id,{step_status:!done?STEP_DONE:STEP_TODO});crowdin.notify(data.error.message||_l("error.internalError"),"error")}}))}},{key:"sortSuggestionTexts",value:function sortSuggestionTexts(){var result=[];if(crowdin.translation){var suggestionTextsSorted=crowdin.translation.suggestionTextsSorted;if(suggestionTextsSorted.hasOwnProperty("default")){result=result.concat(suggestionTextsSorted["default"])}if(suggestionTextsSorted.hasOwnProperty("mt")){result=result.concat(suggestionTextsSorted.mt)}if(suggestionTextsSorted.hasOwnProperty("external")){result=result.concat(suggestionTextsSorted.external)}}return result}}]);return crowdin_translation_helper}(CrowdinComponent);
  