-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from wikimedia/lang-switching-T207709
Switch displayed labels and field values on change of source or target language
- Loading branch information
Showing
11 changed files
with
102 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Add ULS to the target-language button. | ||
*/ | ||
$( function () { | ||
var targetLangButton, | ||
$targetLangButton = $( '.target-lang-widget' ); | ||
if ( $targetLangButton.length === 0 ) { | ||
// If the widget isn't present, do nothing. | ||
return; | ||
} | ||
function onSelectTargetLang( language ) { | ||
// Save the language name and code in the widget. | ||
this.setLabel( $.uls.data.languages[ language ][ 2 ] ); | ||
this.setData( language ); | ||
// Also switch what's displayed in the form when a new language is selected in the ULS. | ||
$( '.translation-fields .oo-ui-fieldLayout' ).each( function () { | ||
var field = OO.ui.infuse( $( this ) ).getField(); | ||
if ( appConfig.translations[ field.data.nodeId ] && | ||
appConfig.translations[ field.data.nodeId ][ language ] | ||
) { | ||
// If there's a translation available, set the field's value. | ||
field.setValue( appConfig.translations[ field.data.nodeId ][ language ].text ); | ||
} else { | ||
// Otherwise, blank the field. | ||
field.setValue( '' ); | ||
} | ||
} ); | ||
} | ||
targetLangButton = OO.ui.infuse( $targetLangButton ); | ||
targetLangButton.$element.uls( { | ||
onSelect: onSelectTargetLang.bind( targetLangButton ), | ||
// Add the preferred languages as the quick-list. | ||
quickList: App.getCookieVal( 'preferredLangs', [] ), | ||
// @HACK: Re-align the ULS menu because we're customizing its layout in translate.less. | ||
left: targetLangButton.$element.offset().left | ||
} ); | ||
} ); | ||
|
||
/** | ||
* Switch displayed 'from' language. | ||
*/ | ||
$( function () { | ||
var sourceLangWidget, | ||
$sourceLangWidget = $( '.source-lang-widget' ); | ||
if ( $sourceLangWidget.length !== 1 ) { | ||
// Don't do anything if the widget isn't present. | ||
return; | ||
} | ||
sourceLangWidget = OO.ui.infuse( $sourceLangWidget[ 0 ] ); | ||
sourceLangWidget.on( 'change', function () { | ||
var newLangCode = sourceLangWidget.getValue(); | ||
// Go through all the field labels and fetch new values from the translations. | ||
$( '.translation-fields .oo-ui-fieldLayout' ).each( function () { | ||
var fieldLayout = OO.ui.infuse( $( this ) ), | ||
nodeId = fieldLayout.getField().data.nodeId, | ||
newLabel = appConfig.translations[ nodeId ][ newLangCode ].text; | ||
fieldLayout.setLabel( newLabel ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
framework: | ||
default_locale: '%locale%' | ||
translator: | ||
enabled: false | ||
default_path: '%kernel.project_dir%/translations' | ||
fallbacks: | ||
- '%locale%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
public/assets/app.09c15a8a.js → public/assets/app.bd8bf375.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace App\Tests\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class TranslateControllerTest extends WebTestCase | ||
{ | ||
|
||
/** | ||
* The translate page. | ||
*/ | ||
public function testExists(): void | ||
{ | ||
$client = static::createClient(); | ||
$crawler = $client->request('GET', '/File:Test.svg'); | ||
$response = $client->getResponse(); | ||
static::assertEquals(200, $response->getStatusCode()); | ||
static::assertContains('Test.svg', $crawler->filter('h1')->text()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters