jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/401820 )

Change subject: Add support for notes languages
......................................................................


Add support for notes languages

Language can be set with note-language attribute.
Available languages now are:
arabic, catalan, deutsch, english, espanol, italiano, nederlands,
norsk, portugues, suomi, svenska, vlaams

Bug: T49604
Change-Id: Idd938089ce12134ac0f045dde7d21b1574d2cf27
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Score.php
M includes/ScoreHooks.php
M modules/ve-score/ve.ui.MWScoreInspector.js
6 files changed, 111 insertions(+), 5 deletions(-)

Approvals:
  Ebe123: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index a64d03f..762f92c 100644
--- a/extension.json
+++ b/extension.json
@@ -42,6 +42,7 @@
                                "score-visualeditor-mwscoreinspector-lang",
                                "score-visualeditor-mwscoreinspector-lang-abc",
                                
"score-visualeditor-mwscoreinspector-lang-lilypond",
+                               
"score-visualeditor-mwscoreinspector-notelanguage",
                                "score-visualeditor-mwscoreinspector-midi",
                                
"score-visualeditor-mwscoreinspector-override-midi",
                                
"score-visualeditor-mwscoreinspector-override-midi-placeholder",
@@ -74,6 +75,9 @@
                "remoteExtPath": "Score/modules"
        },
        "Hooks": {
+               "BeforePageDisplay": [
+                       "ScoreHooks::onBeforePageDisplay"
+               ],
                "ParserFirstCallInit": [
                        "ScoreHooks::onParserFirstCallInit"
                ],
diff --git a/i18n/en.json b/i18n/en.json
index 05d1242..b0697c7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -15,7 +15,9 @@
        "score-error-category-desc": "There was an error while rendering the 
score.",
        "score-getcwderr": "Unable to obtain current working directory",
        "score-invalidlang": "Invalid score language 
lang=\"<nowiki>$1</nowiki>\". Currently recognized languages are 
lang=\"lilypond\" (the default) and lang=\"ABC\".",
+       "score-invalidnotelanguage": "Invalid 
note-language=\"<nowiki>$1</nowiki>\". Currently recognized note languages are: 
$2",
        "score-invalidaudiooverride": "The file \"<nowiki>$1</nowiki>\" you 
specified with override_audio is invalid. Please specify the file name only, 
omit <nowiki>[[…]]</nowiki> and the \"{{ns:file}}:\" prefix.",
+       "score-notelanguagewithraw": "Attribute \"note-language\" cannot be 
used for raw mode scores",
        "score-midioverridenotfound": "The file \"<nowiki>$1</nowiki>\" you 
specified with override_midi could not be found. Please specify the file name 
only, omit <nowiki>[[…]]</nowiki> and the \"{{ns:file}}:\" prefix.",
        "score-noabcinput": "ABC source file $1 could not be created.",
        "score-noimages": "No score images were generated. Please check your 
score code.",
@@ -41,6 +43,7 @@
        "score-visualeditor-mwscoreinspector-lang": "Language",
        "score-visualeditor-mwscoreinspector-lang-abc": "ABC",
        "score-visualeditor-mwscoreinspector-lang-lilypond": "LilyPond",
+       "score-visualeditor-mwscoreinspector-notelanguage": "Notation Language",
        "score-visualeditor-mwscoreinspector-midi": "A link to a MIDI file 
(auto-generated by default)",
        "score-visualeditor-mwscoreinspector-override-midi": "Use an existing 
MIDI file",
        "score-visualeditor-mwscoreinspector-override-midi-placeholder": "Name 
of existing MIDI file",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ed816ad..7c4bb35 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -21,7 +21,9 @@
        "score-error-category-desc": "Description on 
[[Special:TrackingCategories]] for the {{msg-mw|score-error-category}} tracking 
category.",
        "score-getcwderr": "Displayed if the extension cannot obtain the 
current working directory.",
        "score-invalidlang": "Displayed if the lang=\"…\" attribute contains an 
unrecognized score language. $1 is the unrecognized language.",
+       "score-invalidnotelanguage": "Displayed if the note-language=\"…\" 
attribute contains an unrecognized note language. $1 is the unrecognized note 
language. $2 is comma separated list of available languages.",
        "score-invalidaudiooverride": "Displayed if the file specified with the 
override_audio=\"…\" attribute is invalid. $1 is the value of the 
override_audio attribute.",
+       "score-notelanguagewithraw": "Displayed if the \"note-language\" 
attribute is used for scores in raw mode",
        "score-midioverridenotfound": "Displayed if the file specified with the 
override_midi=\"…\" attribute could not be found. $1 is the value of the 
override_midi attribute.",
        "score-noabcinput": "Displayed if an ABC source file could not be 
created for lang=\"ABC\". $1 is the path to the file that could not be 
created.",
        "score-noimages": "Displayed if no score images were rendered.",
@@ -47,6 +49,7 @@
        "score-visualeditor-mwscoreinspector-lang": "Label for the lang 
attribute of the score node\n{{Identical|Language}}",
        "score-visualeditor-mwscoreinspector-lang-abc": "Label for the 'ABC' 
value of the lang attribute",
        "score-visualeditor-mwscoreinspector-lang-lilypond": "Label for the 
'LilyPond' value of the lang attribute",
+       "score-visualeditor-mwscoreinspector-notelanguage": "Label for the 
notation-language attribute of the score node",
        "score-visualeditor-mwscoreinspector-midi": "Label for the midi 
attribute of the score node",
        "score-visualeditor-mwscoreinspector-override-midi": "Label for the 
override_midi attribute of the score node",
        "score-visualeditor-mwscoreinspector-override-midi-placeholder": 
"Placeholder for the label for the override_midi attribute of the score node",
diff --git a/includes/Score.php b/includes/Score.php
index 18b2596..9010605 100644
--- a/includes/Score.php
+++ b/includes/Score.php
@@ -45,6 +45,30 @@
        private static $supportedLangs = [ 'lilypond', 'ABC' ];
 
        /**
+        * Supported note languages.
+        * Key is LilyPond filename. Value is native word
+        */
+       public static $supportedNoteLanguages = [
+               'arabic' => 'العربية',
+               'catalan' => 'Català',
+               'deutsch' => 'Deutsch',
+               'english' => 'English',
+               'espanol' => 'Español',
+               'italiano' => 'Italiano',
+               'nederlands' => 'Nederlands',
+               'norsk' => 'Norsk',
+               'portugues' => 'Português',
+               'suomi' => 'Suomi',
+               'svenska' => 'Svenska',
+               'vlaams' => 'Flemish',
+       ];
+
+       /**
+        * Default language used for notes.
+        */
+       public static $defaultNoteLanguage = 'nederlands';
+
+       /**
         * LilyPond version string.
         * It defaults to null and is set the first time it is required.
         */
@@ -242,6 +266,25 @@
                        // Raw rendering?
                        $options['raw'] = array_key_exists( 'raw', $args );
 
+                       /* Note language selection */
+                       if ( array_key_exists( 'note-language', $args ) ) {
+                               if ( !$options['raw'] ) {
+                                       $options['note-language'] = 
$args['note-language'];
+                               } else {
+                                       throw new ScoreException( wfMessage( 
'score-notelanguagewithraw' ) );
+                               }
+                       } else {
+                               $options['note-language'] = 
self::$defaultNoteLanguage;
+                       }
+                       if ( !in_array( $options['note-language'], array_keys( 
self::$supportedNoteLanguages ) ) ) {
+                               throw new ScoreException(
+                                       wfMessage( 'score-invalidnotelanguage' 
)->plaintextParams(
+                                               $options['note-language'],
+                                               join( ', ', array_keys( 
self::$supportedNoteLanguages ) )
+                                       )
+                               );
+                       }
+
                        /* Override audio file? */
                        if ( array_key_exists( 'override_audio', $args )
                                || array_key_exists( 'override_ogg', $args ) ) {
@@ -280,6 +323,7 @@
                        $cacheOptions = [
                                'code' => $code,
                                'lang' => $options['lang'],
+                               'note-language' => $options['note-language'],
                                'raw'  => $options['raw'],
                                'ExtVersion' => self::CACHE_VERSION,
                                'LyVersion' => self::getLilypondVersion(),
@@ -342,6 +386,7 @@
         *      - audio_name: string If override_audio is true, the audio file 
name
         *      - raw: bool Whether to assume raw LilyPond code. Ignored if the
         *              language is not lilypond, required otherwise.
+        *      - note-language: language to use for notes (one of supported by 
LilyPond)
         *
         * @return string HTML.
         *
@@ -531,7 +576,7 @@
                        if ( $options['raw'] ) {
                                $lilypondCode = $code;
                        } else {
-                               $lilypondCode = self::embedLilypondCode( $code 
);
+                               $lilypondCode = self::embedLilypondCode( $code, 
$options['note-language'] );
                        }
                        $rc = file_put_contents( $factoryLy, $lilypondCode );
                        if ( $rc === false ) {
@@ -708,12 +753,13 @@
         * Embeds simple LilyPond code in a score block.
         *
         * @param string $lilypondCode Simple LilyPond code.
+        * @param string $noteLanguage Language of notes.
         *
         * @return string Raw lilypond code.
         *
         * @throws ScoreException if determining the LilyPond version fails.
         */
-       private static function embedLilypondCode( $lilypondCode ) {
+       private static function embedLilypondCode( $lilypondCode, $noteLanguage 
) {
                $version = self::getLilypondVersion();
 
                // Check if parameters have already been supplied (hybrid-raw 
mode)
@@ -741,6 +787,7 @@
        indent = 0\mm
 }
 \\version "$version"
+\\language "$noteLanguage"
 \\score {
        $lilypondCode
        $options
diff --git a/includes/ScoreHooks.php b/includes/ScoreHooks.php
index 94d00a3..34d053e 100644
--- a/includes/ScoreHooks.php
+++ b/includes/ScoreHooks.php
@@ -22,4 +22,22 @@
                        // LilyPond executable can't found
                }
        }
+
+       /**
+        * Adds needed config variables to the output.
+        *
+        * This is attached to the MediaWiki 'BeforePageDisplay' hook.
+        *
+        * @param OutputPage &$output The page view.
+        * @param Skin &$skin The skin that's going to build the UI.
+        * @return bool Always true.
+        */
+       public static function onBeforePageDisplay( OutputPage &$output, Skin 
&$skin ) {
+               $output->addJsConfigVars( [
+                       'wgScoreNoteLanguages' => 
Score::$supportedNoteLanguages,
+                       'wgScoreDefaultNoteLanguage' => 
Score::$defaultNoteLanguage,
+               ] );
+               return true;
+       }
+
 }
diff --git a/modules/ve-score/ve.ui.MWScoreInspector.js 
b/modules/ve-score/ve.ui.MWScoreInspector.js
index 1c1e8d6..ab0fbf6 100644
--- a/modules/ve-score/ve.ui.MWScoreInspector.js
+++ b/modules/ve-score/ve.ui.MWScoreInspector.js
@@ -39,11 +39,12 @@
  * @inheritdoc
  */
 ve.ui.MWScoreInspector.prototype.initialize = function () {
-       var inputField, langField,
+       var inputField, langField, noteLanguageField,
                midiField, overrideMidiField,
                vorbisField, overrideOggField,
                rawField,
-               notationTabPanel, audioTabPanel, midiTabPanel, advancedTabPanel;
+               notationTabPanel, audioTabPanel, midiTabPanel, advancedTabPanel,
+               language, languages = mw.config.get( 'wgScoreNoteLanguages' );
 
        // Parent method
        ve.ui.MWScoreInspector.super.prototype.initialize.call( this );
@@ -101,6 +102,15 @@
                ]
        } );
 
+       // Note Language
+       this.noteLanguageDropdown = new OO.ui.DropdownWidget();
+       for ( language in languages ) {
+               this.noteLanguageDropdown.getMenu().insertItem( new 
OO.ui.MenuOptionWidget( {
+                       data: language,
+                       label: languages[ language ]
+               } ) );
+       }
+
        // Checkboxes
        this.midiCheckbox = new OO.ui.CheckboxInputWidget();
        this.audioCheckbox = new OO.ui.CheckboxInputWidget();
@@ -122,6 +132,10 @@
        langField = new OO.ui.FieldLayout( this.langSelect, {
                align: 'left',
                label: ve.msg( 'score-visualeditor-mwscoreinspector-lang' )
+       } );
+       noteLanguageField = new OO.ui.FieldLayout( this.noteLanguageDropdown, {
+               align: 'left',
+               label: ve.msg( 
'score-visualeditor-mwscoreinspector-notelanguage' )
        } );
        vorbisField = new OO.ui.FieldLayout( this.audioCheckbox, {
                align: 'inline',
@@ -150,6 +164,7 @@
        notationTabPanel.$element.append(
                inputField.$element,
                langField.$element,
+               noteLanguageField.$element,
                this.generatedContentsError.$element
        );
        audioTabPanel.$element.append(
@@ -176,6 +191,7 @@
                .next( function () {
                        var attributes = this.selectedNode.getAttribute( 'mw' 
).attrs,
                                lang = attributes.lang || 'lilypond',
+                               noteLanguage = attributes[ 'note-language' ] || 
mw.config.get( 'wgScoreDefaultNoteLanguage' ),
                                raw = attributes.raw !== undefined,
                                midi = attributes.midi === '1',
                                vorbis = attributes.vorbis === '1',
@@ -186,6 +202,7 @@
 
                        // Populate form
                        this.langSelect.selectItemByData( lang );
+                       this.noteLanguageDropdown.getMenu().selectItemByData( 
noteLanguage );
                        this.rawCheckbox.setSelected( raw );
                        this.midiCheckbox.setSelected( midi );
                        // vorbis is only set to 1 if an audio file is being 
auto-generated, but
@@ -197,17 +214,20 @@
 
                        // Disable any fields that should be disabled
                        this.toggleDisableRawCheckbox();
+                       this.toggleDisableNoteLanguageDropdown();
                        this.toggleDisableOverrideMidiInput();
                        this.toggleDisableOverrideOggInput();
 
                        // Add event handlers
                        this.langSelect.on( 'choose', this.onChangeHandler );
+                       this.noteLanguageDropdown.on( 'labelChange', 
this.onChangeHandler );
                        this.rawCheckbox.on( 'change', this.onChangeHandler );
                        this.midiCheckbox.on( 'change', this.onChangeHandler );
                        this.audioCheckbox.on( 'change', this.onChangeHandler );
                        this.overrideMidiInput.on( 'change', 
this.onChangeHandler );
                        this.overrideOggInput.on( 'change', 
this.onChangeHandler );
 
+                       this.rawCheckbox.connect( this, { change: 
'toggleDisableNoteLanguageDropdown' } );
                        this.indexLayout.connect( this, { set: 'onTabPanelSet' 
} );
                        this.indexLayout.connect( this, { set: 'updateSize' } );
                        this.langSelect.connect( this, { choose: 
'toggleDisableRawCheckbox' } );
@@ -223,6 +243,7 @@
        return ve.ui.MWScoreInspector.super.prototype.getTeardownProcess.call( 
this, data )
                .first( function () {
                        this.langSelect.off( 'choose', this.onChangeHandler );
+                       this.noteLanguageDropdown.off( 'labelChange', 
this.onChangeHandler );
                        this.midiCheckbox.off( 'change', this.onChangeHandler );
                        this.audioCheckbox.off( 'change', this.onChangeHandler 
);
                        this.overrideMidiInput.off( 'change', 
this.onChangeHandler );
@@ -239,13 +260,14 @@
  * @inheritdoc
  */
 ve.ui.MWScoreInspector.prototype.updateMwData = function ( mwData ) {
-       var lang, raw, midi, vorbis, overrideMidi, overrideOgg;
+       var lang, noteLanguage, raw, midi, vorbis, overrideMidi, overrideOgg;
 
        // Parent method
        ve.ui.MWScoreInspector.super.prototype.updateMwData.call( this, mwData 
);
 
        // Get data from inspector
        lang = this.langSelect.getSelectedItem().getData();
+       noteLanguage = 
this.noteLanguageDropdown.getMenu().getSelectedItem().getData();
        raw = !this.rawCheckbox.isDisabled() && this.rawCheckbox.isSelected();
        // audioCheckbox is selected if an audio file is being included, 
whether that file
        // is being auto-generated or whether an existing file is being used; 
but the "vorbis"
@@ -260,6 +282,7 @@
 
        // Update attributes
        mwData.attrs.lang = lang;
+       mwData.attrs[ 'note-language' ] = raw ? undefined : noteLanguage;
        mwData.attrs.raw = raw ? '1' : undefined;
        mwData.attrs.midi = midi ? '1' : undefined;
        mwData.attrs.vorbis = vorbis ? '1' : undefined;
@@ -278,6 +301,14 @@
 };
 
 /**
+ * Set the disabled status of this.noteLanguage based on the raw attribute
+ */
+ve.ui.MWScoreInspector.prototype.toggleDisableNoteLanguageDropdown = function 
() {
+       // Disable the dropdown if raw mode is used
+       this.noteLanguageDropdown.setDisabled( this.rawCheckbox.isSelected() );
+};
+
+/**
  * Set the disabled status of this.overrideMidiInput based on the midi 
attribute
  */
 ve.ui.MWScoreInspector.prototype.toggleDisableOverrideMidiInput = function () {

-- 
To view, visit https://gerrit.wikimedia.org/r/401820
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idd938089ce12134ac0f045dde7d21b1574d2cf27
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Score
Gerrit-Branch: master
Gerrit-Owner: Phantom42 <[email protected]>
Gerrit-Reviewer: Ebe123 <[email protected]>
Gerrit-Reviewer: Phantom42 <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to