{"version":3,"sources":["transposh.js"],"sourcesContent":["/* Copyright © 2009-2018 Transposh Team (website : http://transposh.org)\n *\n *\tThis program is free software; you can redistribute it and/or modify\n *\tit under the terms of the GNU General Public License as published by\n *\tthe Free Software Foundation; either version 2 of the License, or\n *\t(at your option) any later version.\n *\n *\tThis program is distributed in the hope that it will be useful,\n *\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n *\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n *\tGNU General Public License for more details.\n *\n *\tYou should have received a copy of the GNU General Public License\n *\talong with this program; if not, write to the Free Software\n *\tFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n */\n\n// List of exposed functions:\n// t_jp.dgpt = do_mass_google_translate;\n// t_jp.dbt = do_mass_bing_translate;\n// t_jp.dyt = do_mass_yandex_translate;\n// t_jp.dat = do_mass_apertium_translate;\n// t_jp.tfl = test_for_lazyrun;\n// t_jp.tfju = test_for_jqueryui;\n// t_jp.at = do_auto_translate;\n\n/*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window, _mstConfig */\n(function ($) { // closure\n var\n // this is the size of strings to queue, we don't want too much there\n BATCH_SIZE = 1024,\n // number of phrases that might be translated\n possibly_translateable,\n // ids of progress bars\n t_jp_prefix = t_jp.prefix,\n // source - 0 is human, 1 google , 2 bing, 3 apertium, 4 yandex, 5 baidu - higher reserved for future engines\n source = 1,\n //Ajax translation\n done_posted = 0, /*Timer for translation aggregation*/ timer, tokens = [], translations = [],\n loadingmsn = 0\n ;\n\n // This function fixes the page, it gets a token and translation and fixes this,\n // since here we only get the automated source, we use this to reduce the code size\n function fix_page(token, translation) {\n // Todo - Probably not needed, but in case we get bad stuff\n if ($.trim(translation).length === 0) {\n return;\n }\n // this is an inner function used to fix the images in the case of being inside the edit mode.\n // if we are not editing, no images will be found and nothing will happen.\n // even if this happens before the edit scripts adds the images, it won't matter as source is changed too and the\n // edit script will fix this\n var fix_image = function () { // handle the image changes\n var img_segment_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_') + 1),\n img = $(\"#\" + t_jp_prefix + \"img_\" + img_segment_id);\n $(\"#\" + t_jp_prefix + img_segment_id).attr('data-source', 1); // source is 1\n img.removeClass('tr-icon-yellow').removeClass('tr-icon-green').addClass('tr-icon-yellow');\n };\n\n // might need to escape the token selectors\n token = token.replace(/([;&,\\.\\+\\*\\~':\"\\!\\^#$%@\\[\\]\\(\\)=>\\|])/g, '\\\\$1');\n //window.console && console.log(token);\n // rewrite text for all matching items at once\n $(\"*[data-orig='\" + token + \"'][data-hidden!='y']\")\n .html(translation)\n .each(fix_image);\n\n // TODO - FIX hidden elements too (need to update father's title)\n $(\"*[data-orig='\" + token + \"'][data-hidden='y']\")\n .attr('data-trans', translation)\n .each(fix_image);\n }\n\n // we have four params, here two are implicit (source =1 auto translate, lang = target language)\n function ajax_translate(token, translation) {\n // we aggregate translations together, 200ms from the last translation we will send the timer\n // so here we remove it so nothing unexpected happens\n clearTimeout(timer);\n // push translations\n tokens.push(token);\n translations.push(translation);\n // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation)\n fix_page(token, translation);\n timer = setTimeout(function () {\n var data = {\n ln0: t_jp.lang, // implicit\n sr0: source, // implicit auto translate... 1 if google, 2 if msn\n action: 'tp_translation',\n items: tokens.length // we can do this here because all tokens will be different\n }, i;\n for (i = 0; i < tokens.length; i += 1) {\n data[\"tk\" + i] = tokens[i];\n data[\"tr\" + i] = translations[i];\n // We are pre-accounting the progress bar here - which is not very nice\n //if (source > 0) {\n done_posted += $(\"*[data-orig='\" + tokens[i].replace(/([;&,\\.\\+\\*\\~':\"\\!\\^#$%@\\[\\]\\(\\)=>\\|])/g, '\\\\$1') + \"']\").length;\n //}\n }\n $.ajax({\n type: \"POST\",\n url: t_jp.ajaxurl,\n data: data,\n success: function () {\n // Success now only updates the save progress bar (green)\n console.window && console.log(done_posted + \"/\" + possibly_translateable + \" translations posted\");\n }\n // we removed the error function, as there is no alert for automated thing, this will silently fail\n // which although bad, is what we can do for now\n });\n translations = [];\n tokens = [];\n }, 200); // wait 200 ms... -- TODO, maybe do - items*3\n }\n\n // happens on traslate success\n function auto_translate_success(token, translation) {\n ajax_translate(token, $(\"