Phantom42 has uploaded a new change for review. ( 
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 i18n/en.json
M i18n/qqq.json
M includes/Score.php
3 files changed, 46 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Score 
refs/changes/20/401820/1

diff --git a/i18n/en.json b/i18n/en.json
index 05d1242..2cb0f3e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -15,6 +15,7 @@
        "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-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.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ed816ad..cc18ba1 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -21,6 +21,7 @@
        "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-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.",
diff --git a/includes/Score.php b/includes/Score.php
index 18b2596..8479a89 100644
--- a/includes/Score.php
+++ b/includes/Score.php
@@ -45,6 +45,29 @@
        private static $supportedLangs = [ 'lilypond', 'ABC' ];
 
        /**
+        * Supported note languages.
+        */
+       private static $supportedNoteLanguages = [
+               'arabic',
+               'catalan',
+               'deutsch',
+               'english',
+               'espanol',
+               'italiano',
+               'nederlands',
+               'norsk',
+               'portugues',
+               'suomi',
+               'svenska',
+               'vlaams'
+       ];
+
+       /**
+        * Default language used for notes.
+        */
+       private static $defaultNoteLanguage = 'nederlands';
+
+       /**
         * LilyPond version string.
         * It defaults to null and is set the first time it is required.
         */
@@ -218,6 +241,21 @@
                                        htmlspecialchars( $options['lang'] ) ) 
);
                        }
 
+                       /* Note language selection */
+                       if ( array_key_exists( 'note-language', $args ) ) {
+                               $options['note-language'] = 
$args['note-language'];
+                       } else {
+                               $options['note-language'] = 
self::$defaultNoteLanguage;
+                       }
+                       if ( !in_array( $options['note-language'], 
self::$supportedNoteLanguages ) ) {
+                               throw new ScoreException(
+                                       wfMessage( 'score-invalidnotelanguage' 
)->plaintextParams(
+                                               $options['note-language'],
+                                               join( ', ', 
self::$supportedNoteLanguages )
+                                       )
+                               );
+                       }
+
                        /* Override MIDI file? */
                        if ( array_key_exists( 'override_midi', $args ) ) {
                                $file = wfFindFile( $args['override_midi'] );
@@ -280,6 +318,7 @@
                        $cacheOptions = [
                                'code' => $code,
                                'lang' => $options['lang'],
+                               'note-language' => $options['note-language'],
                                'raw'  => $options['raw'],
                                'ExtVersion' => self::CACHE_VERSION,
                                'LyVersion' => self::getLilypondVersion(),
@@ -342,6 +381,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 +571,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 +748,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 +782,7 @@
        indent = 0\mm
 }
 \\version "$version"
+\\language "$noteLanguage"
 \\score {
        $lilypondCode
        $options

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd938089ce12134ac0f045dde7d21b1574d2cf27
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Score
Gerrit-Branch: master
Gerrit-Owner: Phantom42 <[email protected]>

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

Reply via email to