Automatic Translate Addon For Loco Translate - Version 1.3.2

Version Description

Download this release

Release Info

Developer Narinder singh
Plugin Icon 128x128 Automatic Translate Addon For Loco Translate
Version 1.3.2
Comparing to
See all releases

Code changes from version 1.3 to 1.3.2

assets/js/loco-js-editor.js CHANGED
@@ -577,37 +577,40 @@ function addAutoTranslationBtn(){
577
  $("#loco-toolbar").find("#cool-auto-translate-btn").remove();
578
  }
579
  const disabledBtn='<fieldset><button title="Buy PRO." id="cool-auto-translate-btn" disabled class="button has-icon icon-translate">Auto Translate</button><div style="max-width:320px; display:inline-block;margin-top: 4px;"><span style="font-size:12px;display:inline-block;margin-left:8px;">You have exceeded free translation limit. In order to extend the limit - <a target="_blank" style="font-size:14px;display:inline-block;margin-left:8px;" target="_blank" href="https://locotranslate.com/addon/loco-automatic-translate-premium-license-key/">Buy Premium License</a></span></div></fieldset>';
580
-
581
- if( ATLT == '' || ATLT["api_key"] == '' || ATLT["api_key"]["atlt_api-key"]=='' ){
 
 
 
 
582
  $("#loco-toolbar").find("#loco-actions")
583
  .append('<fieldset><button title="Add API key to enable this feature." id="cool-auto-translate-btn" disabled class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="https://tech.yandex.com/translate/">Get Free API Key</a></fieldset>');
584
  return;
585
- }else if( ATLT["info"]["allowed"]=="no" && ATLT["info"]["type"]=='free'){
586
  $("#loco-toolbar").find("#loco-actions")
587
  .append(disabledBtn);
588
  return;
589
- }else if(ATLT["info"]["today"]!==undefined && parseInt(ATLT["info"]["today"])>300000 && ATLT["info"]["type"]=='free'){
590
  $("#loco-toolbar").find("#loco-actions")
591
  .append(disabledBtn);
592
  return;
593
- }else if(ATLT["info"]["total"]!==undefined && parseInt(ATLT["info"]["total"])>10000000
594
- && ATLT["info"]["type"]=='free'){
595
  $("#loco-toolbar").find("#loco-actions")
596
  .append(disabledBtn);
597
  return;
598
  }else if( window.locoEditorStats.totalTranslated != "100%" && window.locoEditorStats.totalWords > 0 ){
599
- if(ATLT["info"]["type"]=='pro' && validLicenseKey(ATLT["info"]["licenseKey"])){
600
  $("#loco-toolbar").find("#loco-actions")
601
  .append('<fieldset><button id="cool-auto-translate-btn" class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="http://translate.yandex.com/">Powered by Yandex.Translate</a></fieldset>');
602
  }else{
603
- if(ATLT["info"]["today"]==undefined){
604
- var today=100000;
605
  }else{
606
- var today=100000-parseInt(ATLT["info"]["today"]);
607
  }
608
- var total=3000000-parseInt(ATLT["info"]["total"]);
609
- var freeBtn='<fieldset><button data-today-limit="'+today+'" data-total-limit="'+total+'" id="cool-auto-translate-btn" class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="http://translate.yandex.com/">Powered by Yandex.Translate</a></fieldset>';
610
-
611
  $("#loco-toolbar").find("#loco-actions").append(freeBtn);
612
  }
613
  } else if( window.locoEditorStats.totalWords == 0){
@@ -624,49 +627,53 @@ $(document).ready(function(){
624
  addAutoTranslationBtn();
625
  }
626
  // main translate handler
627
- let translationObj = {};
628
  $(document)
629
  // Bind translate function to translate button
630
  .on("click", "#cool-auto-translate-btn", function() {
631
  var thisBtn=$(this);
632
- var todayLimit= thisBtn.data('today-limit');
633
- var totalLimit= thisBtn.data('total-limit');
634
  // const targetLang=conf.locale.lang;
635
- const apiKey = ATLT["api_key"]["lat_api-key"];
636
 
637
  if(locoRawData!=undefined && locoRawData.length>0 && apiKey!='' ){
638
- let untranslatedTextArr=locoRawData.filter((item,index)=>{
639
  // if(item.target===undefined || item.target=="" && savedIndex<=90){
640
  if( (item.target===undefined || item.target=="") && (item.source).includes('</') == false && (item.source).includes('/>') == false && (item.source).includes('#') == false ){
641
  return true;
642
  }else{
643
  HtmlStrings++;
 
 
 
 
 
 
 
 
644
  }
645
-
646
  });
647
- var countWords=untranslatedTextArr.length;
648
- if(countWords>parseInt(todayLimit)){
 
 
 
 
 
 
649
  alert('Your translation string are larger then available free limit.In order to extend limit Buy Pro license key');
650
  }else{
651
  thisBtn.text('...Translating');
652
- translationObj = {
653
- sourceLang:'en',
654
- targetLang:conf['locale']["lang"],
655
  textToTranslateArr:untranslatedTextArr,
656
- orginalArr:conf.podata,
657
- apiKey:apiKey,
658
  thisBtn:$(this),
659
- saveBtn: $('[data-loco="save"]')
660
  };
661
- if (translationObj.targetLang !== null && translationObj.textToTranslateArr !== null) {
662
- var countChars=0;
663
- untranslatedTextArr.map(function(index){
664
- countChars +=index.source.length;
665
- });
666
-
667
- window.locoEditorStats.untranslatedTextArr = translationObj;
668
  jQuery(document).trigger('atlt_translated');
669
- //atlt_translate(translationObj);
670
  // load raw message data
671
 
672
  } //
@@ -679,10 +686,13 @@ $(document).ready(function(){
679
  });
680
 
681
  jQuery(document).on('atlt_translated',function(){
682
- let textToTranslate = window.locoEditorStats.untranslatedTextArr.textToTranslateArr
683
  let totalTranslated = window.locoEditorStats.totalTranslated
684
  const apiKey = ATLT["api_key"]["atlt_api-key"];
685
  const nonce=ATLT["nonce"];
 
 
 
686
  let indexRequest = 50;
687
  if( ATLT.api_key['atlt_index-per-request'] != "" && typeof ATLT.api_key['atlt_index-per-request'] != "undefined" ){
688
  indexRequest = ATLT.api_key['atlt_index-per-request'];
@@ -690,23 +700,20 @@ jQuery(document).on('atlt_translated',function(){
690
 
691
  if( typeof textToTranslate == "object" && textToTranslate.length >= 1 ){
692
  let translationO = {
693
- sourceLang:'en',
694
- targetLang:conf['locale']["lang"],
695
  textToTranslateArr:textToTranslate.slice(indexRequest),
696
- orginalArr:conf.podata,
697
- apiKey:apiKey,
698
- thisBtn:window.locoEditorStats.untranslatedTextArr.thisBtn,
699
- saveBtn: $('[data-loco="save"]')
700
  };
701
- window.locoEditorStats.untranslatedTextArr = translationO;
 
 
702
  let data = {
703
  sourceLang:'en',
704
- targetLang:conf['locale']["lang"],
705
  textToTranslateArr:textToTranslate.slice(0,indexRequest),
706
- orginalArr:conf.podata,
707
  apiKey:apiKey,
708
- thisBtn:window.locoEditorStats.untranslatedTextArr.thisBtn,
709
- saveBtn: $('[data-loco="save"]'),
710
  nonce:nonce
711
  };
712
 
@@ -839,7 +846,7 @@ function atlt_translate(data) {
839
  }).addClass('po-unsaved');
840
  }
841
 
842
- if( (window.locoEditorStats.untranslatedTextArr.textToTranslateArr).length == 0){
843
  data.thisBtn.text('Translated');
844
  data.thisBtn.attr('disabled','disabled');
845
  // change cursor to 'default' state
@@ -852,34 +859,6 @@ function atlt_translate(data) {
852
  });
853
  }
854
 
855
- // Abstract API request function
856
- function makeApiRequest(data, type) {
857
- // send text to translate
858
- url = "https://translate.yandex.net/api/v1.5/tr.json/translate";
859
- url += "?key=" + data.apiKey;
860
- url += "&lang="+data.sourceLang+'-'+ data.targetLang;
861
- url += createEncodedString(data.textToTranslateArr);
862
-
863
- // Return response from API
864
-
865
- const newArr=data.textToTranslateArr.map((item)=>{
866
- if(item.source!==undefined){
867
- return obj={text:item.source};
868
- }
869
- });
870
- return $.ajax({
871
- url: url,
872
- type: type || "GET",
873
- dataType:'jsonp',
874
- data:newArr,
875
- crossDomain:true,
876
- headers: {
877
- "Content-Type": "application/json",
878
- Accept: "application/json"
879
- }
880
- });
881
- }
882
-
883
  function atlt_arrayUnique(array) {
884
  var a = array.concat();
885
  for(var i=0; i<a.length; ++i) {
@@ -892,6 +871,14 @@ function atlt_arrayUnique(array) {
892
  return a;
893
  }
894
 
 
 
 
 
 
 
 
 
895
  function atlt_ajax_translation_request(data,type){
896
 
897
  const newArr=data.textToTranslateArr.map((item)=>{
@@ -918,14 +905,7 @@ function atlt_ajax_translation_request(data,type){
918
  });
919
  }
920
 
921
- // refresh page on save only if there are pending translation
922
- /* jQuery(document).on('poSave',function(){
923
- if( locoEditorStats.totalTranslated != "100%" ){
924
- setTimeout(function(){ window.location.reload(); }, 500);
925
- }
926
- }) */
927
-
928
- // ok, editor ready
929
  updateStatus();
930
 
931
  // clean up
577
  $("#loco-toolbar").find("#cool-auto-translate-btn").remove();
578
  }
579
  const disabledBtn='<fieldset><button title="Buy PRO." id="cool-auto-translate-btn" disabled class="button has-icon icon-translate">Auto Translate</button><div style="max-width:320px; display:inline-block;margin-top: 4px;"><span style="font-size:12px;display:inline-block;margin-left:8px;">You have exceeded free translation limit. In order to extend the limit - <a target="_blank" style="font-size:14px;display:inline-block;margin-left:8px;" target="_blank" href="https://locotranslate.com/addon/loco-automatic-translate-premium-license-key/">Buy Premium License</a></span></div></fieldset>';
580
+ const apiKey=ATLT["api_key"]["atlt_api-key"];
581
+ const userType=ATLT["info"].type;
582
+ const allowed=ATLT["info"].allowed;
583
+ const today=ATLT["info"].today;
584
+ const total=ATLT["info"].total;
585
+ if( ATLT == '' || ATLT["api_key"] == '' || apiKey=='' ){
586
  $("#loco-toolbar").find("#loco-actions")
587
  .append('<fieldset><button title="Add API key to enable this feature." id="cool-auto-translate-btn" disabled class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="https://tech.yandex.com/translate/">Get Free API Key</a></fieldset>');
588
  return;
589
+ }else if( allowed=="no" && userType=='free'){
590
  $("#loco-toolbar").find("#loco-actions")
591
  .append(disabledBtn);
592
  return;
593
+ }else if(today!==undefined && parseInt(today)>300000 && userType=='free'){
594
  $("#loco-toolbar").find("#loco-actions")
595
  .append(disabledBtn);
596
  return;
597
+ }else if(total!==undefined && parseInt(total)>10000000
598
+ && userType=='free'){
599
  $("#loco-toolbar").find("#loco-actions")
600
  .append(disabledBtn);
601
  return;
602
  }else if( window.locoEditorStats.totalTranslated != "100%" && window.locoEditorStats.totalWords > 0 ){
603
+ if(userType=='pro' && validLicenseKey(ATLT["info"]["licenseKey"])){
604
  $("#loco-toolbar").find("#loco-actions")
605
  .append('<fieldset><button id="cool-auto-translate-btn" class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="http://translate.yandex.com/">Powered by Yandex.Translate</a></fieldset>');
606
  }else{
607
+ if(today==undefined){
608
+ var todayChars=100000;
609
  }else{
610
+ var todayChars=100000-parseInt(today);
611
  }
612
+ var totalChars=3000000-parseInt(total);
613
+ var freeBtn='<fieldset><button data-today-limit="'+todayChars+'" data-total-limit="'+totalChars+'" id="cool-auto-translate-btn" class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="http://translate.yandex.com/">Powered by Yandex.Translate</a></fieldset>';
 
614
  $("#loco-toolbar").find("#loco-actions").append(freeBtn);
615
  }
616
  } else if( window.locoEditorStats.totalWords == 0){
627
  addAutoTranslationBtn();
628
  }
629
  // main translate handler
630
+ let dataObj = {};
631
  $(document)
632
  // Bind translate function to translate button
633
  .on("click", "#cool-auto-translate-btn", function() {
634
  var thisBtn=$(this);
635
+ var todayLimit= thisBtn.data('today-limit');
636
+ var totalLimit= thisBtn.data('total-limit');
637
  // const targetLang=conf.locale.lang;
638
+ const apiKey = ATLT["api_key"]["atlt_api-key"];
639
 
640
  if(locoRawData!=undefined && locoRawData.length>0 && apiKey!='' ){
641
+ let untranslatedAllString=locoRawData.filter((item,index)=>{
642
  // if(item.target===undefined || item.target=="" && savedIndex<=90){
643
  if( (item.target===undefined || item.target=="") && (item.source).includes('</') == false && (item.source).includes('/>') == false && (item.source).includes('#') == false ){
644
  return true;
645
  }else{
646
  HtmlStrings++;
647
+ }
648
+ });
649
+ // remove links from string
650
+ let untranslatedTextArr=untranslatedAllString.filter((item,index)=>{
651
+ if(ValidURL(item.source)){
652
+ return false;
653
+ }else{
654
+ return true;
655
  }
 
656
  });
657
+
658
+ if (untranslatedTextArr !== null) {
659
+ var countChars=0;
660
+ untranslatedTextArr.map(function(index){
661
+ countChars +=index.source.length;
662
+ });
663
+
664
+ if(countChars>parseInt(todayLimit)){
665
  alert('Your translation string are larger then available free limit.In order to extend limit Buy Pro license key');
666
  }else{
667
  thisBtn.text('...Translating');
668
+
669
+ dataObj = {
 
670
  textToTranslateArr:untranslatedTextArr,
 
 
671
  thisBtn:$(this),
 
672
  };
673
+
674
+ window.locoEditorStats.dataObj = dataObj;
 
 
 
 
 
675
  jQuery(document).trigger('atlt_translated');
676
+
677
  // load raw message data
678
 
679
  } //
686
  });
687
 
688
  jQuery(document).on('atlt_translated',function(){
689
+ let textToTranslate = window.locoEditorStats.dataObj.textToTranslateArr
690
  let totalTranslated = window.locoEditorStats.totalTranslated
691
  const apiKey = ATLT["api_key"]["atlt_api-key"];
692
  const nonce=ATLT["nonce"];
693
+ const saveBtn=$('[data-loco="save"]');
694
+ const orignalstringArr=conf.podata;
695
+ const targetLang=conf['locale']["lang"];
696
  let indexRequest = 50;
697
  if( ATLT.api_key['atlt_index-per-request'] != "" && typeof ATLT.api_key['atlt_index-per-request'] != "undefined" ){
698
  indexRequest = ATLT.api_key['atlt_index-per-request'];
700
 
701
  if( typeof textToTranslate == "object" && textToTranslate.length >= 1 ){
702
  let translationO = {
 
 
703
  textToTranslateArr:textToTranslate.slice(indexRequest),
704
+ thisBtn:window.locoEditorStats.dataObj.thisBtn,
 
 
 
705
  };
706
+ window.locoEditorStats.dataObj = translationO;
707
+
708
+ // partial data request
709
  let data = {
710
  sourceLang:'en',
711
+ targetLang:targetLang,
712
  textToTranslateArr:textToTranslate.slice(0,indexRequest),
713
+ orginalArr:orignalstringArr,
714
  apiKey:apiKey,
715
+ thisBtn:window.locoEditorStats.dataObj.thisBtn,
716
+ saveBtn:saveBtn,
717
  nonce:nonce
718
  };
719
 
846
  }).addClass('po-unsaved');
847
  }
848
 
849
+ if( (window.locoEditorStats.dataObj.textToTranslateArr).length == 0){
850
  data.thisBtn.text('Translated');
851
  data.thisBtn.attr('disabled','disabled');
852
  // change cursor to 'default' state
859
  });
860
  }
861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
862
  function atlt_arrayUnique(array) {
863
  var a = array.concat();
864
  for(var i=0; i<a.length; ++i) {
871
  return a;
872
  }
873
 
874
+ function ValidURL(str) {
875
+ var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
876
+ if(!pattern.test(str)) {
877
+ return false;
878
+ } else {
879
+ return true;
880
+ }
881
+ }
882
  function atlt_ajax_translation_request(data,type){
883
 
884
  const newArr=data.textToTranslateArr.map((item)=>{
905
  });
906
  }
907
 
908
+ // ok, editor ready
 
 
 
 
 
 
 
909
  updateStatus();
910
 
911
  // clean up
assets/js/loco-js-editor.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(window,$){var TotalCharacters=0,HtmlStrings=0,requestChars=0;let event;document.createEvent("event").initEvent("atlt_translated");let popup_html='<div id="atlt-dialog-container"><div style="display:none;" id="atlt-dialog" title="Automatic Translation Progress"><p><span class="translated-label">Translated</span> <span class="translated-text">0%</span></p><div class="atlt-progress-bar-track"><div class="atlt-progress-bar-value"></div></div><div class="atlt-final-message"></div><button style="display:none;" class="atlt-ok button button-primary">OK</button></div></div>';$("body").append(popup_html),$("#atlt-dialog .atlt-ok.button").on("click",(function(){$("#atlt-dialog").parent(".ui-dialog").hide()}));var loco=window.locoScope,conf=window.locoConf,syncParams=null,saveParams=null,translator=loco.l10n,sprintf=loco.string.sprintf,locale=conf.locale,messages=loco.po.init(locale).wrap(conf.powrap),template=!locale,elForm=document.getElementById("loco-actions"),filePath=conf.popath,syncPath=conf.potpath,elFilesys=document.getElementById("loco-fs"),fsConnect=elFilesys&&loco.fs.init(elFilesys),readonly,editable=!conf.readonly,editor,saveButton,innerDiv=document.getElementById("loco-editor-inner");function doSyncAction(callback){function onSuccess(result){var info=[],doc=messages,exp=result.po,src=result.pot,pot=loco.po.init().load(exp),done=doc.merge(pot),nadd=done.add.length,ndel=done.del.length,t=translator;editor.load(doc),nadd||ndel?(src?info.push(sprintf(t._("Merged from %s"),src)):info.push(t._("Merged from source code")),nadd&&info.push(sprintf(t._n("1 new string added","%s new strings added",nadd),nadd)),ndel&&info.push(sprintf(t._n("1 obsolete string removed","%s obsolete strings removed",ndel),ndel)),$(innerDiv).trigger("poUnsaved",[]),updateStatus(),window.console&&debugMerge(console,done)):src?info.push(sprintf(t._("Already up to date with %s"),src)):info.push(t._("Already up to date with source code")),loco.notices.success(info.join(". ")),$(innerDiv).trigger("poMerge",[result]),callback&&callback()}loco.ajax.post("sync",syncParams,onSuccess,callback)}function debugMerge(console,result){for(var i=-1,t=result.add.length;++i<t;)console.log(" + "+result.add[i].source());for(i=-1,t=result.del.length;++i<t;)console.log(" - "+result.del[i].source())}function doSaveAction(callback){function onSuccess(result){callback&&callback(),editor.save(!0),$("#loco-po-modified").text(result.datetime||"[datetime error]")}saveParams.locale=String(messages.locale()||""),fsConnect&&fsConnect.applyCreds(saveParams),saveParams.data=String(messages),loco.ajax.post("save",saveParams,onSuccess,callback)}function saveIfDirty(){editor.dirty&&doSaveAction()}function onUnloadWarning(){return translator._("Your changes will be lost if you continue without saving")}function registerSaveButton(button){function disable(){button.disabled=!0}function enable(){button.disabled=!1}function think(){disable(),$(button).addClass("loco-loading")}function unthink(){enable(),$(button).removeClass("loco-loading")}return saveButton=button,editor.on("poUnsaved",(function(){enable(),$(button).addClass("button-primary loco-flagged")})).on("poSave",(function(){disable(),$(button).removeClass("button-primary loco-flagged")})),saveParams=$.extend({path:filePath},conf.project||{}),$(button).click((function(event){return event.preventDefault(),think(),doSaveAction(unthink),!1})),!0}function registerSyncButton(button){var project=conf.project;if(project){function disable(){button.disabled=!0}function enable(){button.disabled=!1}function think(){disable(),$(button).addClass("loco-loading")}function unthink(){enable(),$(button).removeClass("loco-loading")}editor.on("poUnsaved",(function(){disable()})).on("poSave",(function(){enable()})),syncParams={bundle:project.bundle,domain:project.domain,type:template?"pot":"po",sync:syncPath||""},$(button).click((function(event){return event.preventDefault(),think(),doSyncAction(unthink),!1})),enable()}return!0}function registerFuzzyButton(button){var toggled=!1,enabled=!1;function redraw(message,state){var allowed=message&&message.translated(0)||!1;enabled!==allowed&&(button.disabled=!allowed,enabled=allowed),state!==toggled&&($(button)[state?"addClass":"removeClass"]("inverted"),toggled=state)}return editor.on("poSelected",(function(event,message){redraw(message,message&&message.fuzzy()||!1)})).on("poEmpty",(function(event,blank,message,pluralIndex){0===pluralIndex&&blank===enabled&&redraw(message,toggled)})).on("poFuzzy",(function(event,message,newState){redraw(message,newState)})),$(button).click((function(event){return event.preventDefault(),editor.fuzzy(!editor.fuzzy()),!1})),!0}function registerRevertButton(button){return editor.on("poUnsaved",(function(){button.disabled=!1})).on("poSave",(function(){button.disabled=!0})),$(button).click((function(event){return event.preventDefault(),location.reload(),!1})),!0}function registerInvisiblesButton(button){var $button=$(button);return button.disabled=!1,editor.on("poInvs",(function(event,state){$button[state?"addClass":"removeClass"]("inverted")})),$button.click((function(event){return event.preventDefault(),editor.setInvs(!editor.getInvs()),!1})),locoScope.tooltip.init($button),!0}function registerCodeviewButton(button){var $button=$(button);return button.disabled=!1,$button.click((function(event){event.preventDefault();var state=!editor.getMono();return editor.setMono(state),$button[state?"addClass":"removeClass"]("inverted"),!1})),locoScope.tooltip.init($button),!0}function registerAddButton(button){return button.disabled=!1,$(button).click((function(event){event.preventDefault();var i=1,baseid,msgid,regex=/(\d+)$/;for(msgid=baseid="New message";messages.get(msgid);)i=regex.exec(msgid)?Math.max(i,RegExp.$1):i,msgid=baseid+" "+ ++i;return editor.add(msgid),!1})),!0}function registerDelButton(button){return button.disabled=!1,$(button).click((function(event){return event.preventDefault(),editor.del(),!1})),!0}function registerDownloadButton(button,id){return button.disabled=!1,$(button).click((function(event){var form=button.form,path=filePath;return"binary"===id&&(path=path.replace(/\.po$/,".mo")),form.path.value=path,form.source.value=messages.toString(),!0})),!0}function noop(event){return event.preventDefault(),!1}function updateStatus(){var t=translator,stats=editor.stats(),total=stats.t,fuzzy=stats.f,empty=stats.u,stext=sprintf(t._n("1 string","%s strings",total),total.format(0)),extra=[];locale&&(stext=sprintf(t._("%s%% translated"),stats.p.replace("%",""))+", "+stext,fuzzy&&extra.push(sprintf(t._("%s fuzzy"),fuzzy.format(0))),empty&&extra.push(sprintf(t._("%s untranslated"),empty.format(0))),extra.length&&(stext+=" ("+extra.join(", ")+")")),$("#loco-po-status").text(stext),void 0===window.locoEditorStats?window.locoEditorStats={totalWords:stats.t,totalTranslated:stats.p}:(window.locoEditorStats.totalWords=stats.t,window.locoEditorStats.totalTranslated=stats.p)}function initSearchFilter(elSearch){function showValidFilter(numFound){$(elSearch.parentNode)[numFound||null==numFound?"removeClass":"addClass"]("invalid")}editor.searchable(loco.fulltext.init()),elSearch.disabled=!1,elSearch.value="";var listener=loco.watchtext(elSearch,(function(value){var numFound;showValidFilter(editor.filter(value,!0))}));editor.on("poFilter",(function(event,value,numFound){listener.val(value||""),showValidFilter(numFound)})).on("poMerge",(function(event,result){var value=listener.val();value&&editor.filter(value)}))}var resize=function(){function top(el,ancestor){for(var y=el.offsetTop||0;(el=el.offsetParent)&&el!==ancestor;)y+=el.offsetTop||0;return y}var fixHeight,minHeight=parseInt($(innerDiv).css("min-height")||0);return function(){var padBottom=20,topBanner=top(innerDiv,document.body),winHeight=window.innerHeight,setHeight=Math.max(minHeight,winHeight-topBanner-20);fixHeight!==setHeight&&(innerDiv.style.height=String(setHeight)+"px",fixHeight=setHeight)}}();resize(),$(window).resize(resize),innerDiv.innerHTML="",editor=loco.po.ed.init(innerDiv).localise(translator),loco.po.kbd.init(editor).add("save",saveIfDirty).enable("copy","clear","enter","next","prev","fuzzy","save","invis");var buttons={save:editable&&registerSaveButton,sync:editable&&registerSyncButton,revert:registerRevertButton,invs:registerInvisiblesButton,code:registerCodeviewButton,source:registerDownloadButton,binary:template?null:registerDownloadButton};function createEncodedString(allStringText){const queryString=allStringText.map(item=>"&text="+encodeURIComponent(item.source)).join(",");return queryString}function validLicenseKey(licenseKey){return licenseKey}function addAutoTranslationBtn(){$("#loco-toolbar").find("#cool-auto-translate-btn").length>0&&$("#loco-toolbar").find("#cool-auto-translate-btn").remove();const disabledBtn='<fieldset><button title="Buy PRO." id="cool-auto-translate-btn" disabled class="button has-icon icon-translate">Auto Translate</button><div style="max-width:320px; display:inline-block;margin-top: 4px;"><span style="font-size:12px;display:inline-block;margin-left:8px;">You have exceeded free translation limit. In order to extend the limit - <a target="_blank" style="font-size:14px;display:inline-block;margin-left:8px;" target="_blank" href="https://locotranslate.com/addon/loco-automatic-translate-premium-license-key/">Buy Premium License</a></span></div></fieldset>',apiKey=ATLT.api_key["atlt_api-key"],userType=ATLT.info.type,allowed=ATLT.info.allowed,today=ATLT.info.today,total=ATLT.info.total;if(""!=ATLT&&""!=ATLT.api_key&&""!=apiKey)if("no"!=allowed||"free"!=userType)if(void 0!==today&&parseInt(today)>3e5&&"free"==userType)$("#loco-toolbar").find("#loco-actions").append(disabledBtn);else if(void 0!==total&&parseInt(total)>1e7&&"free"==userType)$("#loco-toolbar").find("#loco-actions").append(disabledBtn);else if("100%"!=window.locoEditorStats.totalTranslated&&window.locoEditorStats.totalWords>0)if("pro"==userType&&validLicenseKey(ATLT.info.licenseKey))$("#loco-toolbar").find("#loco-actions").append('<fieldset><button id="cool-auto-translate-btn" class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="http://translate.yandex.com/">Powered by Yandex.Translate</a></fieldset>');else{if(null==today)var todayChars=1e5;else var todayChars=1e5-parseInt(today);var totalChars,freeBtn='<fieldset><button data-today-limit="'+todayChars+'" data-total-limit="'+(3e6-parseInt(total))+'" id="cool-auto-translate-btn" class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="http://translate.yandex.com/">Powered by Yandex.Translate</a></fieldset>';$("#loco-toolbar").find("#loco-actions").append(freeBtn)}else{if(0==window.locoEditorStats.totalWords)return;$("#loco-toolbar").find("#loco-actions").append('<fieldset><button id="cool-auto-translate-btn" class="button has-icon icon-translate" disabled>Translated</button></fieldset>')}else $("#loco-toolbar").find("#loco-actions").append(disabledBtn);else $("#loco-toolbar").find("#loco-actions").append('<fieldset><button title="Add API key to enable this feature." id="cool-auto-translate-btn" disabled class="button has-icon icon-translate">Auto Translate</button> <a style="font-size:9px;display:block;margin-left:8px;" target="_blank" href="https://tech.yandex.com/translate/">Get Free API Key</a></fieldset>')}function atlt_translate(data){atlt_ajax_translation_request(data,"POST").success((function(resp){const json_resp=JSON.parse(resp);if(0==json_resp)alert("Unable to make request to the server at the moment. Try again later.");else if(void 0===typeof json_resp.code||200!=json_resp.code){let error="";switch(json_resp.code){case 401:error="Yendex API Key is invalid!";break;case 402:error="Provided Yendex API Key has been blocked!";break;case 404:error="Exceeded the daily limit for Yendex API on the amount of translated text.";break;case 422:error="The text cannot be translated by Yendex API.";break;case 501:error="Yendex API does not support the specified translation direction.";break;default:error=json_resp.message}return void(""!=error&&0!=data.textToTranslateArr.length&&($("#atlt-dialog .atlt-final-message").html("<strong>"+error+"</strong>"),$("#atlt-dialog .atlt-ok.button").show(),data.thisBtn.text("Translation"),data.thisBtn.attr("disabled","disabled")))}let totalTranslated=window.locoEditorStats.totalTranslated;var response=json_resp.text;if(void 0!==response)for(i=0;i<response.length;i++){var text=response[i];if(void 0===data.textToTranslateArr[i])break;data.textToTranslateArr[i].target=text}for(var mergeTranslatedText=atlt_arrayUnique(data.textToTranslateArr.concat(data.orginalArr)),textForTranslation=data.textToTranslateArr,Emptytargets=[],x=0;x<textForTranslation.length;++x)""!=textForTranslation[x].target&&(Emptytargets[x]=textForTranslation[x].source);if((messages=loco.po.init(locale).wrap(conf.powrap)).load(mergeTranslatedText),editor.on("poUnsaved",(function(){window.onbeforeunload=onUnloadWarning})).on("poSave",(function(){updateStatus(),window.onbeforeunload=null})).on("poUpdate",updateStatus),editor.load(messages),data.saveBtn.addClass("button-primary loco-flagged").removeAttr("disabled"),updateStatus(),requestChars=0,$("#atlt-dialog .translated-label").text("Translated"),$("#atlt-dialog .translated-text").text(window.locoEditorStats.totalTranslated),$("#atlt-dialog .atlt-progress-bar-value").width(window.locoEditorStats.totalTranslated),void 0!==json_resp.stats.time_saved)var saved_time_msg='<br/><br/><span style="border: 3px solid #14b75d;display: inline-block;padding: 3px;">Wahooo! You have saved your <strong>'+json_resp.stats.time_saved+"</strong> via auto translating "+parseInt(json_resp.stats.totalChars)+' characters using <strong><a href="https://wordpress.org/support/plugin/automatic-translator-addon-for-loco-translate/reviews/#new-post" target="_new">Loco Automatic Translate Addon</a></strong>.</span><br/><br/>';switch(window.locoEditorStats.totalTranslated){case"0%":$("#atlt-dialog .translated-label").text("Translating..."),$("#atlt-dialog .translated-text").text("");break;case"100%":return data.thisBtn.text("Translated"),data.thisBtn.attr("disabled","disabled"),$("#atlt-dialog .atlt-final-message").html("<strong style='font-size:18px;display:inline-block;margin:5px auto;'>Translation Complete!</strong><br/>(Close this popup & Click <strong>Save</strong>)"+saved_time_msg),void $("#atlt-dialog .atlt-ok.button").show()}for(var x=0;x<=Emptytargets.length;x++){var source=Emptytargets[x];jQuery("#po-list-tbody div[for='po-list-col-source'] div").filter((function(index){return jQuery(this).text()==source})).addClass("po-unsaved")}if(0==window.locoEditorStats.dataObj.textToTranslateArr.length)return data.thisBtn.text("Translated"),data.thisBtn.attr("disabled","disabled"),$("#atlt-dialog .atlt-final-message").html("<strong style='font-size:18px;display:inline-block;margin:5px auto;'>Translation Complete!</strong><br/>(Close this popup & Click <strong>Save</strong>)<br/><br/>Text with HTML content can not be translated."+saved_time_msg),void $("#atlt-dialog .atlt-ok.button").show();jQuery(document).trigger("atlt_translated")}))}function atlt_arrayUnique(array){for(var a=array.concat(),i=0;i<a.length;++i)for(var j=i+1;j<a.length;++j)a[i]===a[j]&&a.splice(j--,1);return a}function ValidURL(str){var pattern;return!!/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(str)}function atlt_ajax_translation_request(data,type){const newArr=data.textToTranslateArr.map(item=>{if(void 0!==item.source)return obj=encodeURI(item.source)});return jQuery.ajax({url:ajaxurl,type:"POST",data:{action:"atlt_translation",sourceLan:data.sourceLang,targetLan:data.targetLang,totalCharacters:TotalCharacters,requestChars:requestChars,nonce:data.nonce,data:newArr},done:function(res){console.log(res)}})}template?(buttons.add=editable&&registerAddButton,buttons.del=editable&&registerDelButton):buttons.fuzzy=registerFuzzyButton,$("#loco-toolbar").find("button").each((function(i,el){var id=el.getAttribute("data-loco"),register=buttons[id];register&&register(el,id)||$(el).hide()})),$(elForm).submit(noop),initSearchFilter(document.getElementById("loco-search")),editor.on("poUnsaved",(function(){window.onbeforeunload=onUnloadWarning})).on("poSave",(function(){updateStatus(),window.onbeforeunload=null})).on("poUpdate",updateStatus),messages.load(conf.podata),editor.load(messages),(locale=editor.targetLocale)?locale.isRTL()&&$(innerDiv).addClass("trg-rtl"):editor.unlock(),$(document).ready((function(){const locoRawData=conf.podata;null!=locoRawData&&locoRawData.length>0&&addAutoTranslationBtn();let dataObj={};$(document).on("click","#cool-auto-translate-btn",(function(){var thisBtn=$(this),todayLimit=thisBtn.data("today-limit"),totalLimit=thisBtn.data("total-limit");const apiKey=ATLT.api_key["atlt_api-key"];if(null!=locoRawData&&locoRawData.length>0&&""!=apiKey){let untranslatedAllString,untranslatedTextArr=locoRawData.filter((item,index)=>{if((void 0===item.target||""==item.target)&&0==item.source.includes("</")&&0==item.source.includes("/>")&&0==item.source.includes("#"))return!0;HtmlStrings++}).filter((item,index)=>!ValidURL(item.source));if(null!==untranslatedTextArr){var countChars=0;untranslatedTextArr.map((function(index){countChars+=index.source.length})),countChars>parseInt(todayLimit)?alert("Your translation string are larger then available free limit.In order to extend limit Buy Pro license key"):(thisBtn.text("...Translating"),dataObj={textToTranslateArr:untranslatedTextArr,thisBtn:$(this)},window.locoEditorStats.dataObj=dataObj,jQuery(document).trigger("atlt_translated"))}}}))})),jQuery(document).on("atlt_translated",(function(){let textToTranslate=window.locoEditorStats.dataObj.textToTranslateArr,totalTranslated=window.locoEditorStats.totalTranslated;const apiKey=ATLT.api_key["atlt_api-key"],nonce=ATLT.nonce,saveBtn=$('[data-loco="save"]'),orignalstringArr=conf.podata,targetLang=conf.locale.lang;let indexRequest=50;if(""!=ATLT.api_key["atlt_index-per-request"]&&void 0!==ATLT.api_key["atlt_index-per-request"]&&(indexRequest=ATLT.api_key["atlt_index-per-request"]),"object"==typeof textToTranslate&&textToTranslate.length>=1){let translationO={textToTranslateArr:textToTranslate.slice(indexRequest),thisBtn:window.locoEditorStats.dataObj.thisBtn};window.locoEditorStats.dataObj=translationO;let data={sourceLang:"en",targetLang:targetLang,textToTranslateArr:textToTranslate.slice(0,indexRequest),orginalArr:orignalstringArr,apiKey:apiKey,thisBtn:window.locoEditorStats.dataObj.thisBtn,saveBtn:saveBtn,nonce:nonce};textToTranslate.slice(0,indexRequest).map((function(value,index){TotalCharacters+=value.source.length,requestChars+=value.source.length})),$("#atlt-dialog").dialog({width:320}),atlt_translate(data)}else HtmlStrings>=1&&(alert("Remaining HTML strings can not be auto translate!"),window.location.reload())})),updateStatus()}(window,jQuery);
automatic-translator-addon-for-loco-translate.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name:Loco Automatic Translate Addon
4
  Description:Auto language translator add-on for Loco Translate plugin to translate plugins and themes translation files into any language via fully automatic machine translations via Yendex Translate API.
5
- Version:1.3
6
  License:GPL2
7
  Text Domain:atlt
8
  Domain Path:languages
@@ -22,7 +22,7 @@ if (!defined('ABSPATH')) {
22
  define('ATLT_FILE', __FILE__);
23
  define('ATLT_URL', plugin_dir_url(ATLT_FILE));
24
  define('ATLT_PATH', plugin_dir_path(ATLT_FILE));
25
- define('ATLT_VERSION', '1.3');
26
 
27
  class LocoAutoTranslate
28
  {
@@ -38,8 +38,9 @@ class LocoAutoTranslate
38
  add_action( 'admin_enqueue_scripts', array( $this, 'atlt_enqueue_scripts') );
39
  add_action('wp_ajax_atlt_translation', array($this, 'atlt_translate_words'), 100);
40
  add_action('init',array($this,'checkStatus'));
41
-
42
-
 
43
  }
44
 
45
 
@@ -61,18 +62,7 @@ class LocoAutoTranslate
61
  include_once ATLT_PATH . 'includes/Helpers/Helpers.php';
62
  include_once ATLT_PATH . 'includes/Core/class.settings-api.php';
63
  include_once ATLT_PATH . 'includes/Core/class.settings-panel.php';
64
-
65
  new Core\Settings_Panel();
66
- //test
67
- // var_dump(Helpers::atlt_time_saved_on_translation(200));
68
- // var_dump(Helpers::atlt_verification());
69
- // delete_transient('atlt_per_day_translated');
70
- //delete_option('atlt_per_day_total_translated');
71
- // delete_option('atlt_grandTotal_translated');
72
-
73
- // $status=Helpers::atltVerification();
74
-
75
- // var_dump($status);
76
  if ( is_admin() ) {
77
  include_once ATLT_PATH . "includes/ReviewNotice/class.review-notice.php";
78
  new ALTLReviewNotice\ALTLReviewNotice();
@@ -180,7 +170,7 @@ class LocoAutoTranslate
180
  function atlt_enqueue_scripts(){
181
 
182
  wp_deregister_script('loco-js-editor');
183
- wp_register_script( 'loco-js-editor', ATLT_URL.'assets/js/loco-js-editor.js', array('loco-js-min-admin'),false, true);
184
 
185
  if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'file-edit') {
186
  $data=array();
@@ -230,11 +220,7 @@ class LocoAutoTranslate
230
  }
231
 
232
  }
233
-
234
- function atlt_load_plugin(){
235
- $atlt=new LocoAutoTranslate();
236
- $atlt->include_files();
237
- }
238
-
239
- add_action( 'plugins_loaded', 'LocoAutoTranslateAddon\atlt_load_plugin' );
240
 
2
  /*
3
  Plugin Name:Loco Automatic Translate Addon
4
  Description:Auto language translator add-on for Loco Translate plugin to translate plugins and themes translation files into any language via fully automatic machine translations via Yendex Translate API.
5
+ Version:1.3.2
6
  License:GPL2
7
  Text Domain:atlt
8
  Domain Path:languages
22
  define('ATLT_FILE', __FILE__);
23
  define('ATLT_URL', plugin_dir_url(ATLT_FILE));
24
  define('ATLT_PATH', plugin_dir_path(ATLT_FILE));
25
+ define('ATLT_VERSION', '1.3.2');
26
 
27
  class LocoAutoTranslate
28
  {
38
  add_action( 'admin_enqueue_scripts', array( $this, 'atlt_enqueue_scripts') );
39
  add_action('wp_ajax_atlt_translation', array($this, 'atlt_translate_words'), 100);
40
  add_action('init',array($this,'checkStatus'));
41
+
42
+ add_action('plugins_loaded', array($this,'include_files'));
43
+
44
  }
45
 
46
 
62
  include_once ATLT_PATH . 'includes/Helpers/Helpers.php';
63
  include_once ATLT_PATH . 'includes/Core/class.settings-api.php';
64
  include_once ATLT_PATH . 'includes/Core/class.settings-panel.php';
 
65
  new Core\Settings_Panel();
 
 
 
 
 
 
 
 
 
 
66
  if ( is_admin() ) {
67
  include_once ATLT_PATH . "includes/ReviewNotice/class.review-notice.php";
68
  new ALTLReviewNotice\ALTLReviewNotice();
170
  function atlt_enqueue_scripts(){
171
 
172
  wp_deregister_script('loco-js-editor');
173
+ wp_register_script( 'loco-js-editor', ATLT_URL.'assets/js/loco-js-editor.min.js', array('loco-js-min-admin'),false, true);
174
 
175
  if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'file-edit') {
176
  $data=array();
220
  }
221
 
222
  }
223
+
224
+ $atlt=new LocoAutoTranslate();
225
+
 
 
 
 
226
 
includes/Feedback/class.feedback-form.php CHANGED
@@ -39,12 +39,6 @@ class FeedbackForm{
39
  |-----------------------------------------------------------------|
40
  */
41
  public function show_deactivate_feedback_popup() {
42
-
43
- if( isset( $GLOBALS['COOL_FEEDBACK_FORM'] ) ){
44
- return;
45
- }
46
- $GLOBALS['COOL_FEEDBACK_FORM'] = true;
47
-
48
  $screen = get_current_screen();
49
  if( !isset( $screen ) || $screen->id != 'plugins' ){
50
  return;
39
  |-----------------------------------------------------------------|
40
  */
41
  public function show_deactivate_feedback_popup() {
 
 
 
 
 
 
42
  $screen = get_current_screen();
43
  if( !isset( $screen ) || $screen->id != 'plugins' ){
44
  return;
includes/Register/LocoAutomaticTranslateAddonPro.php CHANGED
@@ -183,7 +183,7 @@ require_once "LocoAutomaticTranslateAddonProBase.php";
183
  <?php
184
  $purchaseEmail = get_option( "LocoAutomaticTranslateAddonPro_lic_email", get_bloginfo( 'admin_email' ));
185
  ?>
186
- <input type="text" class="regular-text code" name="el_license_email" size="50" value="<?php echo $purchaseEmail; ?>" placeholder="" required="required">
187
  <div><small><?php _e("✅ I agree to share my purchase code and email for plugin verification and to receive future updates notifications!",$this->slug);?></small></div>
188
  </div>
189
  <div class="el-license-active-btn">
183
  <?php
184
  $purchaseEmail = get_option( "LocoAutomaticTranslateAddonPro_lic_email", get_bloginfo( 'admin_email' ));
185
  ?>
186
+ <input type="text" class="regular-text code" name="el_license_email" size="50" value="<?php echo sanitize_email($purchaseEmail); ?>" placeholder="" required="required">
187
  <div><small><?php _e("✅ I agree to share my purchase code and email for plugin verification and to receive future updates notifications!",$this->slug);?></small></div>
188
  </div>
189
  <div class="el-license-active-btn">
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags:loco,translate,translation,translator,localization,language,translations,lo
4
  Requires at least:4.5
5
  Tested up to:5.3
6
  Requires PHP:5.6
7
- Stable tag:1.3
8
  License:GPLv2 or later
9
  License URI:http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -14,9 +14,9 @@ Automatic language translator add-on for Loco Translate plugin to translate Word
14
 
15
  **Automatic Machine Translator Addon For Loco Translate**
16
 
17
- Install this plugin along with the famous **[Loco Translate](https://wordpress.org/plugins/loco-translate/)** plugin (**1,000,000+ Active Installations**) and automatically machine translate any WordPress plugin or theme translation files into any language.
18
 
19
- = Loco Addon Features (Locotranslate.com): =
20
  * One-click translate any plugin or theme all translatable strings.
21
  * You can automatic translate upto **300,000 characters** daily free of cost (you can extend this limit via [premium license key](https://locotranslate.com/addon/loco-automatic-translate-premium-license-key/)).
22
  * Check auto translations inside Loco build-in editor to manually edit any machine translated string.
@@ -73,6 +73,14 @@ For **premium license** users:- The volume of the text translated: 1,000,000 cha
73
  3. Free License v/s Premium License
74
 
75
  == Changelog ==
 
 
 
 
 
 
 
 
76
  <strong>Version 1.3 | 03 DEC 2019</strong>
77
  <pre>
78
  Added: Integrated translated characters stats tables
4
  Requires at least:4.5
5
  Tested up to:5.3
6
  Requires PHP:5.6
7
+ Stable tag:trunk
8
  License:GPLv2 or later
9
  License URI:http://www.gnu.org/licenses/gpl-2.0.html
10
 
14
 
15
  **Automatic Machine Translator Addon For Loco Translate**
16
 
17
+ Install this plugin along with the famous **[Loco Translate](https://wordpress.org/plugins/loco-translate/)** plugin (**900,000+ Active Installations**) and automatically machine translate any WordPress plugin or theme translation files into any language.
18
 
19
+ = Loco Addon Features ([LocoTranslate.com](https://locotranslate.com)): =
20
  * One-click translate any plugin or theme all translatable strings.
21
  * You can automatic translate upto **300,000 characters** daily free of cost (you can extend this limit via [premium license key](https://locotranslate.com/addon/loco-automatic-translate-premium-license-key/)).
22
  * Check auto translations inside Loco build-in editor to manually edit any machine translated string.
73
  3. Free License v/s Premium License
74
 
75
  == Changelog ==
76
+ <strong>Version 1.3.2 | 13 DEC 2019</strong>
77
+ <pre>
78
+ Added:Integrated URL and link filters in String
79
+ Added: Added string filters
80
+ Improved: JS code
81
+ Improved: feedback from
82
+ Improved: minor issues
83
+ </pre>
84
  <strong>Version 1.3 | 03 DEC 2019</strong>
85
  <pre>
86
  Added: Integrated translated characters stats tables