From d1a6592185cddb38df14a03a3a69c44dda1c525a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Tisza?= Date: Tue, 22 Apr 2014 21:55:57 +0000 Subject: [PATCH] Add more survey languages (fr, de, pt/pr-br) For pt speakers pt-br is shown until we get a pt translation Related core commit: If2c57846f4dfb05ea58f36b25e3d8185d2a6e70e Change-Id: I595446dc59c1bca2ea0b977be9d26f17192d3bc4 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/481 --- resources/mmv/ui/mmv.ui.stripeButtons.js | 13 ++++++++----- .../qunit/mmv/ui/mmv.ui.stripeButtons.test.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/resources/mmv/ui/mmv.ui.stripeButtons.js b/resources/mmv/ui/mmv.ui.stripeButtons.js index 6fafaee4c..5278970b2 100644 --- a/resources/mmv/ui/mmv.ui.stripeButtons.js +++ b/resources/mmv/ui/mmv.ui.stripeButtons.js @@ -192,14 +192,17 @@ * @param {string|null} langcode */ SBP.getFeedbackSurveyBaseUrlForLanguage = function ( langcode ) { - var baseUrl = 'https://www.surveymonkey.com/s/media-viewer-1', - surveyTranslations = { ca: 1, hu: 1 }; + var baseLangcode, + baseUrl = 'https://www.surveymonkey.com/s/media-viewer-1', + surveyTranslations = { ca: 'ca', hu: 'hu', fr: 'fr', pt: 'pt-br', 'pt-br': 'pt-br', de: 'de' }; - langcode = langcode.split( /[_-]/ )[0]; // get rid of variants - if ( langcode === 'en') { + baseLangcode = langcode.split( /[_-]/ )[0]; // get rid of variants + if ( baseLangcode === 'en') { return baseUrl; } else if ( surveyTranslations[langcode] ) { - return baseUrl + '-' + langcode; + return baseUrl + '-' + surveyTranslations[langcode]; + } else if ( surveyTranslations[baseLangcode] ) { + return baseUrl + '-' + surveyTranslations[baseLangcode]; } else { return null; } diff --git a/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js b/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js index 11ca67b79..389f0c73f 100644 --- a/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js @@ -82,6 +82,25 @@ mw.config.set( 'wgUserLanguage', oldLanguage ); } ); + QUnit.test( 'getFeedbackSurveyBaseUrlForLanguage()', 7, function ( assert ) { + var buttons = createStripeButtons(); + + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'en' ), + 'https://www.surveymonkey.com/s/media-viewer-1', 'Base survey URL for english' ); + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'hu' ), + 'https://www.surveymonkey.com/s/media-viewer-1-hu', 'Language code appended for supported languages' ); + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'el' ), + null, 'Null for non-supported languages' ); + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'en-gb' ), + 'https://www.surveymonkey.com/s/media-viewer-1', 'Base survey URL for english variants' ); + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'fr-xx' ), + 'https://www.surveymonkey.com/s/media-viewer-1-fr', 'Base code appended for other variants' ); + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'pt-br' ), + 'https://www.surveymonkey.com/s/media-viewer-1-pt-br', 'Full code appended if the variant itself is supported' ); + assert.strictEqual( buttons.getFeedbackSurveyBaseUrlForLanguage( 'pt' ), + 'https://www.surveymonkey.com/s/media-viewer-1-pt-br', 'Temporary special case for pt' ); + } ); + QUnit.test( 'set()/empty() sanity test:', 1, function ( assert ) { var buttons = createStripeButtons(), fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' },