Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/102118
Change subject: TranslateSandbox: Refactor code for showing translations of a new user ...................................................................... TranslateSandbox: Refactor code for showing translations of a new user Moved the code to showTranlations and showTranslation methods Change-Id: Ia736d624f127e534a3d03b0e2bf0c59d86fb32ec --- M resources/js/ext.translate.special.translatesandbox.js 1 file changed, 65 insertions(+), 61 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/18/102118/1 diff --git a/resources/js/ext.translate.special.translatesandbox.js b/resources/js/ext.translate.special.translatesandbox.js index 4933d3b..caf8a37 100644 --- a/resources/js/ext.translate.special.translatesandbox.js +++ b/resources/js/ext.translate.special.translatesandbox.js @@ -150,78 +150,82 @@ // @todo: move higher in the tree storage = new mw.translate.TranslationStashStorage(); - storage.getUserTranslations( request.username ).done( function ( translations ) { - var $target = $( '.translations' ); + storage.getUserTranslations( request.username ).done( showTranslations ); + } - $target.empty(); + function showTranslations( translations ) { + var $target = $( '.translations' ); - // Display a message if the user didn't make any translations - if ( !translations.translationstash.translations.length ) { - $target.append( - $( '<div>' ) - .addClass( 'tsb-details-no-translations' ) - .text( mw.msg( 'tsb-didnt-make-any-translations' ) ) - ); + $target.empty(); - return; - } - + // Display a message if the user didn't make any translations + if ( !translations.translationstash.translations.length ) { $target.append( $( '<div>' ) - .addClass( 'row title' ) - .append( - $( '<div>' ) - .text( mw.msg( 'tsb-translations-source' ) ) - .addClass( 'four columns' ), - $( '<div>' ) - .text( mw.msg( 'tsb-translations-user' ) ) - .addClass( 'four columns' ), - $( '<div>' ) - .text( mw.msg( 'tsb-translations-current' ) ) - .addClass( 'four columns' ) - ) - ); + .addClass( 'tsb-details-no-translations' ) + .text( mw.msg( 'tsb-didnt-make-any-translations' ) ) + ); - translations.translationstash.translations.sort( sortTranslationsByLanguage ); + return; + } - $.each( translations.translationstash.translations, function( index, translation ) { - var translationLang = translation.title.split( '/' ).pop(); - - $target.append( + $target.append( + $( '<div>' ) + .addClass( 'row title' ) + .append( $( '<div>' ) - .addClass( 'row' ) - .append( - $( '<div>' ) - .addClass( 'four columns source' ) - .text( translation.definition ), - $( '<div>' ) - .addClass( 'four columns translation' ) - .append( - $( '<div>' ).text( translation.translation ), - $( '<div>' ) - .addClass( 'info autonym' ) - .prop( { - dir: $.uls.data.getDir( translationLang ), - lang: translationLang - } ) - .text( - $.uls.data.getAutonym( translationLang ) - ) - ), - $( '<div>' ) - .addClass( 'four columns comparison' ) - .append( - $( '<div>' ).text( translation.comparison || '' ), - $( '<div>' ) - .addClass( 'info' ) - .text( translation.title ) - ) - ) - ); - } ); + .text( mw.msg( 'tsb-translations-source' ) ) + .addClass( 'four columns' ), + $( '<div>' ) + .text( mw.msg( 'tsb-translations-user' ) ) + .addClass( 'four columns' ), + $( '<div>' ) + .text( mw.msg( 'tsb-translations-current' ) ) + .addClass( 'four columns' ) + ) + ); + translations.translationstash.translations.sort( sortTranslationsByLanguage ); + $.each( translations.translationstash.translations, function( index, translation ) { + showTranslation( translation ); } ); } + function showTranslation( translation ) { + var $target = $( '.translations' ), + translationLang = translation.title.split( '/' ).pop(); + + $target.append( $( '<div>' ) + .addClass( 'row' ) + .append( + $( '<div>' ) + .addClass( 'four columns source' ) + .text( translation.definition ), + $( '<div>' ) + .addClass( 'four columns translation' ) + .append( + $( '<div>' ).text( translation.translation ), + $( '<div>' ) + .addClass( 'info autonym' ) + .prop( { + dir: $.uls.data.getDir( translationLang ), + lang: translationLang + } ) + .text( + $.uls.data.getAutonym( translationLang ) + ) + ), + $( '<div>' ) + .addClass( 'four columns comparison' ) + .append( + $( '<div>' ).text( translation.comparison || '' ), + $( '<div>' ) + .addClass( 'info' ) + .text( translation.title ) + ) + ) + ); + } + /** * Display when multiple requests are checked */ -- To view, visit https://gerrit.wikimedia.org/r/102118 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia736d624f127e534a3d03b0e2bf0c59d86fb32ec Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits