Skip to content

Commit

Permalink
Handle non-existing target languages in upload check
Browse files Browse the repository at this point in the history
Make sure the original target translation exists before using it
to check whether we can upload to Commons.

Bug: T220618
  • Loading branch information
samwilson committed Apr 11, 2019
1 parent cdf46b8 commit df4e29a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions assets/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $( window ).on( 'load', function () {
$( '.translation-fields .oo-ui-fieldLayout .oo-ui-inputWidget' ).each( function () {
var inputWiget = OO.ui.infuse( $( this ) ),
$imgElement = $( '#translation-image img' ),
targetLangWidget = OO.ui.infuse( $( '.target-lang-widget' ) ),
targetLang = OO.ui.infuse( $( '.target-lang-widget' ) ).getValue(),
updatePreviewImage = function () {
var requestParams = {},
canUpload = false,
Expand All @@ -132,17 +132,22 @@ $( window ).on( 'load', function () {
$( '.image-column' ).addClass( 'loading' );
// Go through all fields and construct the request parameters.
$( '.translation-fields .oo-ui-fieldLayout' ).each( function () {
var fieldLayout = OO.ui.infuse( $( this ) ),
var textChanged,
originalText = '',
fieldLayout = OO.ui.infuse( $( this ) ),
tspanId = fieldLayout.getField().data[ 'tspan-id' ],
text = fieldLayout.getField().getValue(),
textChanged = text !== '' && text !== appConfig.translations[ tspanId ][ targetLangWidget.getValue() ].text;
text = fieldLayout.getField().getValue();
if ( appConfig.translations[ tspanId ][ targetLang ] !== undefined ) {
originalText = appConfig.translations[ tspanId ][ targetLang ].text;
}
textChanged = text !== '' && text !== originalText;
requestParams[ tspanId ] = text;
canUpload = canUpload || ( textChanged && appConfig.loggedIn );
} );
// Update the image.
$.ajax( {
type: 'POST',
url: appConfig.baseUrl + 'api/translate/' + $imgElement.data( 'filename' ) + '/' + targetLangWidget.getValue(),
url: appConfig.baseUrl + 'api/translate/' + $imgElement.data( 'filename' ) + '/' + targetLang,
data: requestParams,
success: function ( result ) {
// Remove the loading class after the image layer has re-loaded.
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"assets/app.3876858b.css"
],
"js": [
"assets/app.2ff9235f.js"
"assets/app.bde6b676.js"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/assets/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"assets/app.css": "assets/app.3876858b.css",
"assets/app.js": "assets/app.2ff9235f.js",
"assets/app.js": "assets/app.bde6b676.js",
"assets/grabbing.cur": "assets/a8c874b93b3d848f39a71260c57e3863.cur",
"assets/grab.cur": "assets/b06c243f534d9c5461d16528156cd5a8.cur",
"assets/i18n/app/af.json": "assets/i18n/app/af.json",
Expand Down

0 comments on commit df4e29a

Please sign in to comment.