diff --git a/README.md b/README.md index 62f3ac0..c38be6f 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,14 @@ Sure! You are welcome to report any issues or add feature suggestions on the [Gi ## Changelog +### Unreleased + +* Use REST API to convert the entire Translation Set on demand. +* Fix original_id error when changing string status. +* Fix i18n of updated count numbers. +* Stricten code. +* Analyse GP Template with PHPStan. + ### 1.4.10 * Tested up to WP 6.7. diff --git a/assets/js/scripts.js b/assets/js/scripts.js index 047660c..f576d16 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -1,9 +1,12 @@ -/* global document, gpConvertPTAO90, setTimeout, wp */ +/* global document, gpConvertPTAO90, Intl, setTimeout, wp */ jQuery( document ).ready( function( $ ) { // Set array of Translation Sets. var translationSets = []; + // Get User Locale. + var userLocale = gpConvertPTAO90.user_locale; + // Check if user is has GlotPress Admin previleges. var glotpressAdmin = gpConvertPTAO90.admin; @@ -96,111 +99,102 @@ jQuery( document ).ready( function( $ ) { var button = $( 'table.gp-table.translation-sets tr[data-locale="' + locale + '"][data-slug="' + slug + '"] td:first-child button.gp-convert-pt-ao90-update-button' ); console.log( 'Clicked to convert project "' + projectPath + '" locale "' + locale + '/' + slug + '"' ); - $.ajax( { + button.attr( 'disabled', true ).removeClass( 'success fail' ).addClass( 'updating' ).children( 'span.label' ).text( wp.i18n.__( 'Syncing...', 'gp-convert-pt-ao90' ) ); - url: gpConvertPTAO90.ajaxurl, - type: 'POST', - data: { - action: 'convert_project', - projectPath: projectPath, - locale: locale, - slug: slug, - nonce: gpConvertPTAO90.nonce, - }, - beforeSend: function() { - console.log( 'Ajax request is starting...' ); - button.attr( 'disabled', true ).removeClass( 'success fail' ).addClass( 'updating' ).children( 'span.label' ).text( wp.i18n.__( 'Syncing...', 'gp-convert-pt-ao90' ) ); - }, + wp.apiFetch( { + path: '/gp-convert-pt-ao90/v1/translation-set/' + projectPath + '/' + locale + '/' + slug + '/-convert', + method: 'POST', + + } ) + .then( function( response ) { + // Set translation set data. + var percent = response.percent; + var current = response.current; + var fuzzy = response.fuzzy; + var untranslated = response.untranslated; + var waiting = response.waiting; + + // For compatibility with GP Toolbox where these columns might be shown. + var old = response.old; + var rejected = response.rejected; + var warnings = response.warnings; + + // Check if GP Toolbox is available. + var gpToolboxUpdateHighlight = wp.hooks.hasAction( 'gpToolboxUpdateHighlight', 'update_highlight_action' ); + + // Check if bubble of more than 90% exist. + var bubbleMoreThan90 = button.closest( 'td' ).children( 'span.bubble.morethan90' ).length; - } ).done( function( response, textStatus, jqXHR ) { - // Set translation set data. - var percent = response.data.percent; - var current = response.data.current; - var fuzzy = response.data.fuzzy; - var untranslated = response.data.untranslated; - var waiting = response.data.waiting; - - // For compatibility with GP Toolbox where these columns might be shown. - var old = response.data.old; - var rejected = response.data.rejected; - var warnings = response.data.warnings; - - // Check if GP Toolbox is available. - var gpToolboxUpdateHighlight = wp.hooks.hasAction( 'gpToolboxUpdateHighlight', 'update_highlight_action' ); - - // Check if bubble of more than 90% exist. - var bubbleMoreThan90 = button.closest( 'td' ).children( 'span.bubble.morethan90' ).length; - - // Set translation set row data. - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.percent' ).text( percent + '%' ); - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.translated a' ).text( current ); - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.fuzzy a' ).text( fuzzy ); - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.untranslated a' ).text( untranslated ); - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.waiting a' ).text( waiting ); - - // Do if GP Toolbox update highlight hook is available. - if ( gpToolboxUpdateHighlight ) { - console.log( 'GP Toolbox gpToolboxUpdateHighlight action is available:', gpToolboxUpdateHighlight ); // Set translation set row data. - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.old a' ).text( old ); - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.rejected a' ).text( rejected ); - $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.warnings a' ).text( warnings ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.percent' ).text( percent + '%' ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.translated a' ).text( Intl.NumberFormat( userLocale.slug ).format( current ) ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.fuzzy a' ).text( Intl.NumberFormat( userLocale.slug ).format( fuzzy ) ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.untranslated a' ).text( Intl.NumberFormat( userLocale.slug ).format( untranslated ) ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.waiting a' ).text( Intl.NumberFormat( userLocale.slug ).format( waiting ) ); + + // Do if GP Toolbox update highlight hook is available. + if ( gpToolboxUpdateHighlight ) { + console.log( 'GP Toolbox gpToolboxUpdateHighlight action is available:', gpToolboxUpdateHighlight ); + // Set translation set row data. + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.old a' ).text( Intl.NumberFormat( userLocale.slug ).format( old ) ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.rejected a' ).text( Intl.NumberFormat( userLocale.slug ).format( rejected ) ); + $( 'table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.warnings a' ).text( Intl.NumberFormat( userLocale.slug ).format( warnings ) ); + + // Trigger the Update Highlight function from GP Toolbox. + wp.hooks.doAction( 'gpToolboxUpdateHighlight' ); + } - // Trigger the Update Highlight function from GP Toolbox. - wp.hooks.doAction( 'gpToolboxUpdateHighlight' ); - } + // Add Bubble of more than 90% if currently doesn't exist. + if ( percent >= 90 ) { + console.log( 'Setting percentage in the morethan90 Bubble: ' + percent + '%' ); - // Add Bubble of more than 90% if currently doesn't exist. - if ( percent >= 90 ) { - console.log( 'Setting percentage in the morethan90 Bubble: ' + percent + '%' ); + // Update current Bubble. + if ( bubbleMoreThan90 ) { + console.log( 'Change Bubble from ' + button.closest( 'td' ).children( 'span.bubble.morethan90' ).text() + ' to ' + percent + '%' ); + $( button ).closest( 'td' ).children( 'span.bubble.morethan90' ).text( percent + '%' ); - // Update current Bubble. - if ( bubbleMoreThan90 ) { - console.log( 'Change Bubble from ' + button.closest( 'td' ).children( 'span.bubble.morethan90' ).text() + ' to ' + percent + '%' ); - $( button ).closest( 'td' ).children( 'span.bubble.morethan90' ).text( percent + '%' ); + // Add new Bubble. + } else { + console.log( 'Add Bubble ' + percent + '%' ); - // Add new Bubble. - } else { - console.log( 'Add Bubble ' + percent + '%' ); + $( '' + percent + '%' + '' ).insertAfter( button.closest( 'td' ).find( 'strong' ) ); + } - $( '' + percent + '%' + '' ).insertAfter( button.closest( 'td' ).find( 'strong' ) ); + // Check if there is a bubble to remove. + } else if ( bubbleMoreThan90 ) { + // Remove Bubble. + $( button ).closest( 'td' ).children( 'span.bubble.morethan90' ).remove(); } - // Check if there is a bubble to remove. - } else if ( bubbleMoreThan90 ) { - // Remove Bubble. - $( button ).closest( 'td' ).children( 'span.bubble.morethan90' ).remove(); - } - - // Change button status to 'Synced'. - button.removeClass( 'updating' ).addClass( 'success' ); - button.children( 'span.icon.dashicons' ).hide().removeClass( 'dashicons-update' ).addClass( 'dashicons-yes' ).show(); - button.children( 'span.label' ).text( wp.i18n.__( 'Synced!', 'gp-convert-pt-ao90' ) ); - - console.log( 'Ajax request has been completed (' + textStatus + '). Status: ' + jqXHR.status + ' ' + jqXHR.statusText ); - console.log( response ); - console.log( textStatus ); - console.log( jqXHR ); - } ).fail( function( jqXHR, textStatus ) { - // Change button status to 'Failed'. - button.removeClass( 'updating' ).addClass( 'fail' ); - button.children( 'span.icon.dashicons' ).hide().removeClass( 'dashicons-update' ).addClass( 'dashicons-warning' ).show(); - button.children( 'span.label' ).text( wp.i18n.__( 'Failed!', 'gp-convert-pt-ao90' ) ); - - // Show the Error notice. - console.log( 'Ajax request has failed (' + textStatus + '). Status: ' + jqXHR.status + ' ' + jqXHR.statusText ); - } ).always( function() { - // Change button status back to default. - setTimeout( - function() { - button.attr( 'disabled', false ).removeClass( 'success fail' ); - button.children( 'span.icon.dashicons' ).hide().removeClass( 'dashicons-yes dashicons-warning' ).addClass( 'dashicons-update' ).show(); - button.children( 'span.label' ).text( wp.i18n.__( 'Sync', 'gp-convert-pt-ao90' ) ); - }, - 3000 // Wait 3 Seconds. - ); - - console.log( 'Ajax end.' ); - } ); + // Change button status to 'Synced'. + button.removeClass( 'updating' ).addClass( 'success' ); + button.children( 'span.icon.dashicons' ).hide().removeClass( 'dashicons-update' ).addClass( 'dashicons-yes' ).show(); + button.children( 'span.label' ).text( wp.i18n.__( 'Synced!', 'gp-convert-pt-ao90' ) ); + + console.log( response ); + } ) + .catch( function( error ) { + // Change button status to 'Failed'. + button.removeClass( 'updating' ).addClass( 'fail' ); + button.children( 'span.icon.dashicons' ).hide().removeClass( 'dashicons-update' ).addClass( 'dashicons-warning' ).show(); + button.children( 'span.label' ).text( wp.i18n.__( 'Failed!', 'gp-convert-pt-ao90' ) ); + + // Show the Error notice. + console.log( 'Failed to convert Translation Set.' ); + console.log( 'Error:', error.message ); + } ) + .finally( function() { + // Change button status back to default. + setTimeout( + function() { + button.attr( 'disabled', false ).removeClass( 'success fail' ); + button.children( 'span.icon.dashicons' ).hide().removeClass( 'dashicons-yes dashicons-warning' ).addClass( 'dashicons-update' ).show(); + button.children( 'span.label' ).text( wp.i18n.__( 'Sync', 'gp-convert-pt-ao90' ) ); + }, + 3000 // Wait 3 Seconds. + ); + + console.log( 'Request ended.' ); + } ); } } ); diff --git a/assets/js/scripts.min.js b/assets/js/scripts.min.js index 5a0a3ff..e0df206 100644 --- a/assets/js/scripts.min.js +++ b/assets/js/scripts.min.js @@ -1,2 +1,2 @@ -jQuery(document).ready(function($){var translationSets=[],glotpressAdmin=gpConvertPTAO90.admin,gpUrlProject=gpConvertPTAO90.gp_url_project;$("table.gp-table.translation-sets tr td:first-child a").each(function(){var regexPattern=new RegExp("^"+gpUrlProject+"(.*).*/(.+)/(.+)/$"),regexPattern=$(this).attr("href").match(regexPattern),locale=regexPattern[2],regexPattern=regexPattern[3],editable=gpConvertPTAO90.edit;translationSets.push(locale),$(this).closest("tr").attr("data-locale",locale),$(this).closest("tr").attr("data-slug",regexPattern),"pt-ao90"===locale&&$(this).closest("tr").attr("data-editable",editable)}),translationSets.includes("pt")&&translationSets.includes("pt-ao90")&&($('table.gp-table.translation-sets tr[data-locale="pt-ao90"] td:first-child a').closest("tr").addClass("variant"),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child').children().last().after(''),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child span.gp-convert-pt-ao90-update').html(''),glotpressAdmin)&&$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child span.gp-convert-pt-ao90-update').children().last().after('"),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child span.gp-convert-pt-ao90-update button.gp-convert-pt-ao90-update-button').on("click",function(){var locale=$(this).closest("tr").attr("data-locale"),slug=$(this).closest("tr").attr("data-slug"),regexPattern=new RegExp("^"+gpUrlProject+"(.*)/"+locale+"/"+slug+"/$");((projectPath,locale,slug)=>{var button=$('table.gp-table.translation-sets tr[data-locale="'+locale+'"][data-slug="'+slug+'"] td:first-child button.gp-convert-pt-ao90-update-button');$.ajax({url:gpConvertPTAO90.ajaxurl,type:"POST",data:{action:"convert_project",projectPath:projectPath,locale:locale,slug:slug,nonce:gpConvertPTAO90.nonce},beforeSend:function(){button.attr("disabled",!0).removeClass("success fail").addClass("updating").children("span.label").text(wp.i18n.__("Syncing...","gp-convert-pt-ao90"))}}).done(function(response,textStatus,jqXHR){var percent=response.data.percent,current=response.data.current,fuzzy=response.data.fuzzy,untranslated=response.data.untranslated,waiting=response.data.waiting,old=response.data.old,rejected=response.data.rejected,response=response.data.warnings,gpToolboxUpdateHighlight=wp.hooks.hasAction("gpToolboxUpdateHighlight","update_highlight_action"),bubbleMoreThan90=button.closest("td").children("span.bubble.morethan90").length;$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.percent').text(percent+"%"),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.translated a').text(current),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.fuzzy a').text(fuzzy),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.untranslated a').text(untranslated),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.waiting a').text(waiting),gpToolboxUpdateHighlight&&($('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.old a').text(old),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.rejected a').text(rejected),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.warnings a').text(response),wp.hooks.doAction("gpToolboxUpdateHighlight")),90<=percent?bubbleMoreThan90?$(button).closest("td").children("span.bubble.morethan90").text(percent+"%"):$(''+percent+"%").insertAfter(button.closest("td").find("strong")):bubbleMoreThan90&&$(button).closest("td").children("span.bubble.morethan90").remove(),button.removeClass("updating").addClass("success"),button.children("span.icon.dashicons").hide().removeClass("dashicons-update").addClass("dashicons-yes").show(),button.children("span.label").text(wp.i18n.__("Synced!","gp-convert-pt-ao90"))}).fail(function(jqXHR,textStatus){button.removeClass("updating").addClass("fail"),button.children("span.icon.dashicons").hide().removeClass("dashicons-update").addClass("dashicons-warning").show(),button.children("span.label").text(wp.i18n.__("Failed!","gp-convert-pt-ao90"))}).always(function(){setTimeout(function(){button.attr("disabled",!1).removeClass("success fail"),button.children("span.icon.dashicons").hide().removeClass("dashicons-yes dashicons-warning").addClass("dashicons-update").show(),button.children("span.label").text(wp.i18n.__("Sync","gp-convert-pt-ao90"))},3e3)})})($(this).closest("td").find("a").attr("href").match(regexPattern)[1],locale,slug)}),$(".translation-sets").tablesorter({theme:"glotpress",sortList:[[2,1]],cssChildRow:"variant",headers:{0:{sorter:"text"}}})}); +jQuery(document).ready(function($){var translationSets=[],userLocale=gpConvertPTAO90.user_locale,glotpressAdmin=gpConvertPTAO90.admin,gpUrlProject=gpConvertPTAO90.gp_url_project;$("table.gp-table.translation-sets tr td:first-child a").each(function(){var regexPattern=new RegExp("^"+gpUrlProject+"(.*).*/(.+)/(.+)/$"),regexPattern=$(this).attr("href").match(regexPattern),locale=regexPattern[2],regexPattern=regexPattern[3],editable=gpConvertPTAO90.edit;translationSets.push(locale),$(this).closest("tr").attr("data-locale",locale),$(this).closest("tr").attr("data-slug",regexPattern),"pt-ao90"===locale&&$(this).closest("tr").attr("data-editable",editable)}),translationSets.includes("pt")&&translationSets.includes("pt-ao90")&&($('table.gp-table.translation-sets tr[data-locale="pt-ao90"] td:first-child a').closest("tr").addClass("variant"),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child').children().last().after(''),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child span.gp-convert-pt-ao90-update').html(''),glotpressAdmin)&&$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child span.gp-convert-pt-ao90-update').children().last().after('"),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td:first-child span.gp-convert-pt-ao90-update button.gp-convert-pt-ao90-update-button').on("click",function(){var locale=$(this).closest("tr").attr("data-locale"),slug=$(this).closest("tr").attr("data-slug"),regexPattern=new RegExp("^"+gpUrlProject+"(.*)/"+locale+"/"+slug+"/$");((projectPath,locale,slug)=>{var button=$('table.gp-table.translation-sets tr[data-locale="'+locale+'"][data-slug="'+slug+'"] td:first-child button.gp-convert-pt-ao90-update-button');button.attr("disabled",!0).removeClass("success fail").addClass("updating").children("span.label").text(wp.i18n.__("Syncing...","gp-convert-pt-ao90")),wp.apiFetch({path:"/gp-convert-pt-ao90/v1/translation-set/"+projectPath+"/"+locale+"/"+slug+"/-convert",method:"POST"}).then(function(response){var percent=response.percent,current=response.current,fuzzy=response.fuzzy,untranslated=response.untranslated,waiting=response.waiting,old=response.old,rejected=response.rejected,response=response.warnings,gpToolboxUpdateHighlight=wp.hooks.hasAction("gpToolboxUpdateHighlight","update_highlight_action"),bubbleMoreThan90=button.closest("td").children("span.bubble.morethan90").length;$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.percent').text(percent+"%"),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.translated a').text(Intl.NumberFormat(userLocale.slug).format(current)),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.fuzzy a').text(Intl.NumberFormat(userLocale.slug).format(fuzzy)),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.untranslated a').text(Intl.NumberFormat(userLocale.slug).format(untranslated)),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.waiting a').text(Intl.NumberFormat(userLocale.slug).format(waiting)),gpToolboxUpdateHighlight&&($('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.old a').text(Intl.NumberFormat(userLocale.slug).format(old)),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.rejected a').text(Intl.NumberFormat(userLocale.slug).format(rejected)),$('table.gp-table.translation-sets tr[data-locale="pt-ao90"][data-slug="default"] td.stats.warnings a').text(Intl.NumberFormat(userLocale.slug).format(response)),wp.hooks.doAction("gpToolboxUpdateHighlight")),90<=percent?bubbleMoreThan90?$(button).closest("td").children("span.bubble.morethan90").text(percent+"%"):$(''+percent+"%").insertAfter(button.closest("td").find("strong")):bubbleMoreThan90&&$(button).closest("td").children("span.bubble.morethan90").remove(),button.removeClass("updating").addClass("success"),button.children("span.icon.dashicons").hide().removeClass("dashicons-update").addClass("dashicons-yes").show(),button.children("span.label").text(wp.i18n.__("Synced!","gp-convert-pt-ao90"))}).catch(function(error){button.removeClass("updating").addClass("fail"),button.children("span.icon.dashicons").hide().removeClass("dashicons-update").addClass("dashicons-warning").show(),button.children("span.label").text(wp.i18n.__("Failed!","gp-convert-pt-ao90"))}).finally(function(){setTimeout(function(){button.attr("disabled",!1).removeClass("success fail"),button.children("span.icon.dashicons").hide().removeClass("dashicons-yes dashicons-warning").addClass("dashicons-update").show(),button.children("span.label").text(wp.i18n.__("Sync","gp-convert-pt-ao90"))},3e3)})})($(this).closest("td").find("a").attr("href").match(regexPattern)[1],locale,slug)}),$(".translation-sets").tablesorter({theme:"glotpress",sortList:[[2,1]],cssChildRow:"variant",headers:{0:{sorter:"text"}}})}); //# sourceMappingURL=scripts.min.js.map \ No newline at end of file diff --git a/assets/js/scripts.min.js.map b/assets/js/scripts.min.js.map index 8528bce..deab77b 100644 --- a/assets/js/scripts.min.js.map +++ b/assets/js/scripts.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["scripts.js"],"names":["jQuery","document","ready","$","translationSets","glotpressAdmin","gpConvertPTAO90","admin","gpUrlProject","gp_url_project","each","regexPattern","RegExp","match","this","attr","locale","slug","editable","edit","push","closest","includes","addClass","children","last","after","html","wp","i18n","__","on","projectPath","button","ajax","url","ajaxurl","type","data","action","nonce","beforeSend","removeClass","text","done","response","textStatus","jqXHR","percent","current","fuzzy","untranslated","waiting","old","rejected","warnings","gpToolboxUpdateHighlight","hooks","hasAction","bubbleMoreThan90","length","doAction","insertAfter","find","remove","hide","show","fail","always","setTimeout","tablesorter","theme","sortList","cssChildRow","headers","0","sorter"],"mappings":"AAEAA,OAAQC,QAAS,EAAEC,MAAO,SAAUC,GAEnC,IAAIC,gBAAkB,GAGlBC,eAAiBC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K,OAAQC,IAAK,CAC3C,CAAE,EAGFd,EAAG,mBAAoB,EAAEmE,YAAa,CACrCC,MAAO,YACPC,SAAU,CAAE,CAAE,EAAG,IACjBC,YAAa,UACbC,QAAS,CACRC,EAAG,CACFC,OAAQ,MACT,CACD,CACD,CAAE,CAwHH,CAAE"} \ No newline at end of file +{"version":3,"sources":["scripts.js"],"names":["jQuery","document","ready","$","translationSets","userLocale","gpConvertPTAO90","user_locale","glotpressAdmin","admin","gpUrlProject","gp_url_project","each","regexPattern","RegExp","match","this","attr","locale","slug","editable","edit","push","closest","includes","addClass","children","last","after","html","wp","i18n","__","on","projectPath","button","removeClass","text","apiFetch","path","method","then","response","percent","current","fuzzy","untranslated","waiting","old","rejected","warnings","gpToolboxUpdateHighlight","hooks","hasAction","bubbleMoreThan90","length","Intl","NumberFormat","format","doAction","insertAfter","find","remove","hide","show","catch","error","finally","setTimeout","tablesorter","theme","sortList","cssChildRow","headers","0","sorter"],"mappings":"AAEAA,OAAQC,QAAS,EAAEC,MAAO,SAAUC,GAEnC,IAAIC,gBAAkB,GAGlBC,WAAaC,gBAAgBC,YAG7BC,eAAiBF,gBAAgBG,MAGjCC,aAAeJ,gBAAgBK,eAGnCR,EAAG,qDAAsD,EAAES,KAAM,WAEhE,IAAIC,aAAe,IAAIC,OAAQ,IAAMJ,aAAe,oBAAqB,EAMrEK,aAAQZ,EAAGa,IAAK,EAAEC,KAAM,MAAO,EAAEF,MAAOF,YAAa,EACrDK,OAASH,aAAM,GACfI,aAAOJ,aAAM,GAGbK,SAAWd,gBAAgBe,KAG/BjB,gBAAgBkB,KAAMJ,MAAO,EAE7Bf,EAAGa,IAAK,EAAEO,QAAS,IAAK,EAAEN,KAAM,cAAeC,MAAO,EACtDf,EAAGa,IAAK,EAAEO,QAAS,IAAK,EAAEN,KAAM,YAAaE,YAAK,EAGlC,YAAXD,QAEJf,EAAGa,IAAK,EAAEO,QAAS,IAAK,EAAEN,KAAM,gBAAiBG,QAAS,CAE5D,CAA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U,OAAOT,SAAU,qBAAsB,EAAEqC,KAAK,EAAE3B,YAAa,kBAAmB,EAAEX,SAAU,eAAgB,EAAEuC,KAAK,EACnH7B,OAAOT,SAAU,YAAa,EAAEW,KAAMP,GAAGC,KAAKC,GAAI,UAAW,oBAAqB,CAAE,CAGrF,CAAE,EACDiC,MAAO,SAAUC,OAEjB/B,OAAOC,YAAa,UAAW,EAAEX,SAAU,MAAO,EAClDU,OAAOT,SAAU,qBAAsB,EAAEqC,KAAK,EAAE3B,YAAa,kBAAmB,EAAEX,SAAU,mBAAoB,EAAEuC,KAAK,EACvH7B,OAAOT,SAAU,YAAa,EAAEW,KAAMP,GAAGC,KAAKC,GAAI,UAAW,oBAAqB,CAAE,CAKrF,CAAE,EACDmC,QAAS,WAETC,WACC,WACCjC,OAAOlB,KAAM,WAAY,CAAA,CAAM,EAAEmB,YAAa,cAAe,EAC7DD,OAAOT,SAAU,qBAAsB,EAAEqC,KAAK,EAAE3B,YAAa,iCAAkC,EAAEX,SAAU,kBAAmB,EAAEuC,KAAK,EACrI7B,OAAOT,SAAU,YAAa,EAAEW,KAAMP,GAAGC,KAAKC,GAAI,OAAQ,oBAAqB,CAAE,CAClF,EACA,GACD,CAGD,CAAE,CACJ,GA9Ha7B,EAAGa,IAAK,EAAEO,QAAS,IAAK,EAAEsC,KAAM,GAAI,EAAE5C,KAAM,MAAO,EAAEF,MAAOF,YAAa,EAC7D,GAEKK,OAAQC,IAAK,CAC3C,CAAE,EAGFhB,EAAG,mBAAoB,EAAEkE,YAAa,CACrCC,MAAO,YACPC,SAAU,CAAE,CAAE,EAAG,IACjBC,YAAa,UACbC,QAAS,CACRC,EAAG,CACFC,OAAQ,MACT,CACD,CACD,CAAE,CA+GH,CAAE"} \ No newline at end of file diff --git a/composer.json b/composer.json index e168fda..5ed1ae5 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "phpcompatibility/phpcompatibility-wp": "^2.1.5", "phpmd/phpmd": "^2.15.0", "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan-strict-rules": "^1.6.1", "sirbrillig/phpcs-variable-analysis": "^2.11.19", "szepeviktor/phpstan-wordpress": "^1.3.5", "wp-coding-standards/wpcs": "^3.1.0" diff --git a/composer.lock b/composer.lock index f36472f..2cf330d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "93369b5ff8afc1e628ef303956d0427b", + "content-hash": "a27fcf8a10518338e696baa9fba58b29", "packages": [ { "name": "pedro-mendonca/convert-pt-ao90", @@ -1615,6 +1615,55 @@ ], "time": "2024-10-18T11:12:07+00:00" }, + { + "name": "phpstan/phpstan-strict-rules", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-strict-rules.git", + "reference": "daeec748b53de80a97498462513066834ec28f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/daeec748b53de80a97498462513066834ec28f8b", + "reference": "daeec748b53de80a97498462513066834ec28f8b", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.12.4" + }, + "require-dev": { + "nikic/php-parser": "^4.13.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Extra strict and opinionated rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/1.6.1" + }, + "time": "2024-09-20T14:04:44+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -1853,16 +1902,16 @@ }, { "name": "symfony/config", - "version": "v5.4.45", + "version": "v5.4.46", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "b9d94b0753da249439694c4a3847f57465b40d1d" + "reference": "977c88a02d7d3f16904a81907531b19666a08e78" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/b9d94b0753da249439694c4a3847f57465b40d1d", - "reference": "b9d94b0753da249439694c4a3847f57465b40d1d", + "url": "https://api.github.com/repos/symfony/config/zipball/977c88a02d7d3f16904a81907531b19666a08e78", + "reference": "977c88a02d7d3f16904a81907531b19666a08e78", "shasum": "" }, "require": { @@ -1912,7 +1961,7 @@ "description": "Helps you find, load, combine, autofill and validate configuration values of any kind", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/config/tree/v5.4.45" + "source": "https://github.com/symfony/config/tree/v5.4.46" }, "funding": [ { @@ -1928,7 +1977,7 @@ "type": "tidelift" } ], - "time": "2024-10-22T13:05:35+00:00" + "time": "2024-10-30T07:58:02+00:00" }, { "name": "symfony/dependency-injection", diff --git a/gp-convert-pt-ao90.php b/gp-convert-pt-ao90.php index 266d6cc..25d25f9 100644 --- a/gp-convert-pt-ao90.php +++ b/gp-convert-pt-ao90.php @@ -66,6 +66,9 @@ // Set Convert PT AO90 for GlotPress file path. define( 'GP_CONVERT_PT_AO90_FILE', plugin_basename( __FILE__ ) ); +// Set the plugin Rest API namespace. +define( 'GP_CONVERT_PT_AO90_REST_NAMESPACE', 'gp-convert-pt-ao90/v1' ); + /** * Disable editing translations for PT AO90. * add_filter( 'gp_convert_pt_ao90_edit', '__return_false' ); diff --git a/gp-templates/translation-row-preview.php b/gp-templates/translation-row-preview.php index 642df1e..6a5b27f 100644 --- a/gp-templates/translation-row-preview.php +++ b/gp-templates/translation-row-preview.php @@ -4,6 +4,17 @@ * * @package GlotPress * @subpackage Templates + * + * @var GP_Locale $locale GlotPress Locale object. + * @var Translation_Entry $translation GlotPress Translation object. + * @var bool $has_root Wether the Locale has a root Locale. + * @var bool $is_ptao90 Wether the Locale is pt_PT_ao90. + * @var bool $supports_variants Wether the Locale supports variants. + * @var array $root_translations Array of the translations from the root Locale. + * @var bool $can_approve Wether the user can approve. + * @var bool $can_approve_translation Wether the user can approve the translation. + * @var bool $can_edit Wether the user can edit. + * @var string $translation_singular The translation singular. */ $priority_char = array( @@ -13,11 +24,17 @@ '1' => array( '↑', 'transparent', 'green' ), ); -if ( $is_ptao90 && ! $supports_variants && GP_CONVERT_PT_AO90_SHOWDIFF && $has_root ) { +$root_translation = null; - $root_translation = null; +if ( $is_ptao90 && ! $supports_variants && defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF && $has_root ) { foreach ( $root_translations as $r_translation ) { + if ( ! property_exists( $translation, 'original_id' ) ) { + continue; + } + if ( ! property_exists( $r_translation, 'original_id' ) ) { + continue; + } if ( $translation->original_id === $r_translation->original_id ) { $root_translation = $r_translation; break; @@ -27,7 +44,7 @@ ?> - + @@ -38,11 +55,14 @@ priority ?? '0'; + $translation_priority_name = is_string( gp_array_get( GP::$original->get_static( 'priorities' ), $translation_priority_id ) ) ? gp_array_get( GP::$original->get_static( 'priorities' ), $translation_priority_id ) : 'normal'; + ?> - + priority ][0]; + echo esc_html( $priority_char[ $translation_priority_id ][0] ); ?> @@ -85,21 +105,21 @@ $missing_text = "$edit_text"; - if ( ! count( array_filter( $translation->translations, 'gp_is_not_null' ) ) ) { + if ( array_filter( $translation->translations, 'gp_is_not_null' ) === array() ) { // Do if no translations found. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $missing_text; - } elseif ( ! $translation->plural || $locale->nplurals === 1 ) { + } elseif ( is_null( $translation->plural ) || $locale->nplurals === 1 ) { // Do if no plurals or number of plurals is 1. $singular_translation = esc_translation( $translation->translations[0] ); // Check if has root. if ( $is_ptao90 && ( isset( $translation->root_id ) || $has_root ) ) { - if ( GP_CONVERT_PT_AO90_SHOWDIFF === true ) { + if ( defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF === true ) { $singular_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( - esc_translation( $supports_variants ? $translation->root_translation_0 : ( ! is_null( $root_translation ) ? $root_translation->translations[0] : '' ) ), + esc_translation( $supports_variants ? property_exists( $translation, 'root_translation_0' ) && $translation->root_translation_0 : ( ! is_null( $root_translation ) ? $root_translation->translations[0] : '' ) ), esc_translation( $translation->translations[0] ) ); } @@ -122,9 +142,9 @@ $singular_translation = esc_translation( $translation->translations[0] ); // Check if has root. if ( $is_ptao90 && ( isset( $translation->root_id ) || $has_root ) ) { - if ( GP_CONVERT_PT_AO90_SHOWDIFF === true ) { + if ( defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF === true ) { $singular_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( - esc_translation( $supports_variants ? $translation->root_translation_0 : ( ! is_null( $root_translation ) ? $root_translation->translations[0] : '' ) ), + esc_translation( $supports_variants ? property_exists( $translation, 'root_translation_0' ) && $translation->root_translation_0 : ( ! is_null( $root_translation ) ? $root_translation->translations[0] : '' ) ), esc_translation( $translation->translations[0] ) ); } @@ -144,9 +164,9 @@ $plural_translation = esc_translation( $translation->translations[1] ); // Check if has root. if ( $is_ptao90 && ( isset( $translation->root_id ) || $has_root ) ) { - if ( GP_CONVERT_PT_AO90_SHOWDIFF === true ) { + if ( defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF === true ) { $plural_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( - esc_translation( $supports_variants ? $translation->root_translation_1 : ( ! is_null( $root_translation ) ? $root_translation->translations[1] : '' ) ), + esc_translation( $supports_variants ? property_exists( $translation, 'root_translation_1' ) && $translation->root_translation_1 : ( ! is_null( $root_translation ) ? $root_translation->translations[1] : '' ) ), esc_translation( $translation->translations[1] ) ); } @@ -186,7 +206,7 @@ $plural_translation = esc_translation( $translation->translations[ $plural_index ] ); // Check if has root. if ( $is_ptao90 && ( isset( $translation->root_id ) || $has_root ) ) { - if ( GP_CONVERT_PT_AO90_SHOWDIFF === true ) { + if ( defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF === true ) { $plural_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $supports_variants ? $translation->{ 'root_translation_' . $plural_index } : ( ! is_null( $root_translation ) ? $root_translation->translations[ $plural_index ] : '' ) ), esc_translation( $translation->translations[ $plural_index ] ) diff --git a/includes/class-portuguese-ao90.php b/includes/class-portuguese-ao90.php index 6aefd71..6d84154 100644 --- a/includes/class-portuguese-ao90.php +++ b/includes/class-portuguese-ao90.php @@ -16,6 +16,8 @@ use GP_Translation; use GP_Translation_Set; use Convert_PT_AO90; +use Translation_Entry; +use Translations; use WP_Error; // Exit if accessed directly. @@ -84,10 +86,8 @@ public static function init() { */ add_filter( 'gp_translation_sets_sort', array( self::class, 'sort_translation_sets' ) ); - /** - * Force convert the whole project again. - */ - add_action( 'wp_ajax_convert_project', array( self::class, 'convert_project' ) ); + // Instantiate Rest API. + new Rest_API(); } @@ -203,8 +203,8 @@ public static function notice_locale_not_found() { * * @since 1.3.0 * - * @param string $template The template name. - * @param array $args Arguments passed to the template. + * @param string $template The template name. + * @param array $args Arguments passed to the template. * * @return void */ @@ -217,7 +217,7 @@ public static function pre_template_load( $template, &$args ) { $is_ptao90 = true; // Check if the the Variant is read-only. - if ( GP_CONVERT_PT_AO90_EDIT === false ) { + if ( defined( 'GP_CONVERT_PT_AO90_EDIT' ) && GP_CONVERT_PT_AO90_EDIT === false ) { // Customize $args on 'translations' template, and also on 'translation-row' to override the $can_approve_translation before loading 'translation-row'. if ( $template === 'translations' || $template === 'translation-row' ) { @@ -275,11 +275,11 @@ public static function pre_template_load( $template, &$args ) { } } - if ( ! $supports_variants && GP_CONVERT_PT_AO90_SHOWDIFF === true && $has_root === true ) { + if ( $supports_variants === false && defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF === true && $has_root === true ) { - $translations = (array) $args['translations']; + $translations = $args['translations']; - if ( count( $translations ) !== 0 ) { + if ( is_array( $translations ) && $translations !== array() ) { $originals = array(); @@ -336,7 +336,7 @@ public static function pre_template_load( $template, &$args ) { $root_translations = null; - if ( ! $supports_variants && GP_CONVERT_PT_AO90_SHOWDIFF === true && $has_root === true ) { + if ( $supports_variants === false && defined( 'GP_CONVERT_PT_AO90_SHOWDIFF' ) && GP_CONVERT_PT_AO90_SHOWDIFF === true && $has_root === true ) { $root_translations = GP::$translation->for_translation( $project, $root_translation_set, @@ -344,7 +344,7 @@ public static function pre_template_load( $template, &$args ) { // Get the current root translation for the row original. array( 'status' => 'current', - 'original_id' => $args['original_id'], + 'original_id' => $args['translation']->original_id, ) ); } @@ -378,7 +378,7 @@ public static function post_template_load( $template, &$args ) { if ( isset( $args['locale_slug'] ) && $args['locale_slug'] === 'pt-ao90' ) { // Check if the the Variant is read-only. - if ( GP_CONVERT_PT_AO90_EDIT === false ) { + if ( defined( 'GP_CONVERT_PT_AO90_EDIT' ) && GP_CONVERT_PT_AO90_EDIT === false ) { // CSS for variant PT AO90. ?>