jenkins-bot has submitted this change and it was merged.

Change subject: Support (poorly) per-language icon versions in colorize-svg.js
......................................................................


Support (poorly) per-language icon versions in colorize-svg.js

Generate additional rules using :lang() selectors. The way we're
doing it means that only very simple selectors will work, but it
is enough for our use case.

Bug: T76539
Change-Id: I47704bf9b643ef6e65f5bc138678439a55090773
---
M build/tasks/colorize-svg.js
1 file changed, 58 insertions(+), 1 deletion(-)

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



diff --git a/build/tasks/colorize-svg.js b/build/tasks/colorize-svg.js
index d02d8c0..0328b34 100644
--- a/build/tasks/colorize-svg.js
+++ b/build/tasks/colorize-svg.js
@@ -170,11 +170,12 @@
                        return fileName;
                }
 
-               var selector, declarations, direction,
+               var selector, declarations, direction, lang, langSelector,
                        deferred = Q.defer(),
                        file = typeof this.file === 'string' ?
                                { default: this.file } :
                                { ltr: this.file.ltr, rtl: this.file.rtl },
+                       moreLangs = this.file.lang || {},
                        name = this.name,
                        sourcePath = this.list.getPath(),
                        destinationPath = destination.getPath(),
@@ -192,6 +193,15 @@
                        uncolorizableImages = [],
                        unknownVariants = [];
 
+               // Expand shorthands:
+               // { "en,de,fr": "foo.svg" } → { "en": "foo.svg", "de": 
"foo.svg", "fr": "foo.svg" }
+               moreLangs = Object.keys( moreLangs ).reduce( function ( langs, 
langList ) {
+                       langList.split( ',' ).forEach( function ( lang ) {
+                               langs[ lang ] = moreLangs[ langList ];
+                       } );
+                       return langs;
+               }, {} );
+
                // Original
                selector = cssSelectors.selectorWithoutVariant
                        .replace( /{prefix}/g, cssClassPrefix )
@@ -206,6 +216,25 @@
                                path.join( sourcePath, file[ direction ] )
                        );
                        files[ path.join( destinationPath, file[ direction ] ) 
] = originalSvg[ direction ];
+
+                       for ( lang in moreLangs ) {
+                               if ( file[ direction ] === moreLangs[ lang ] ) {
+                                       continue;
+                               }
+
+                               // This will not work for selectors ending in a 
pseudo-element.
+                               langSelector = ':lang(' + lang + ')';
+                               declarations = getDeclarations( moreLangs[ lang 
] );
+                               rules[ direction ].push(
+                                       selector.replace( /,|$/g, langSelector 
+ '$&' ) +
+                                       ' {\n\t' + declarations + '\n}'
+                               );
+
+                               originalSvg[ 'lang-' + lang ] = grunt.file.read(
+                                       path.join( sourcePath, moreLangs[ lang 
] )
+                               );
+                               files[ path.join( destinationPath, moreLangs[ 
lang ] ) ] = originalSvg[ 'lang-' + lang ];
+                       }
                }
 
                // Variants
@@ -242,6 +271,34 @@
                                        variantizeFileName( file[ direction ], 
variantName )
                                );
                                files[ destinationFilePath ] = variantSvg;
+
+                               for ( lang in moreLangs ) {
+                                       if ( file[ direction ] === moreLangs[ 
lang ] ) {
+                                               continue;
+                                       }
+
+                                       langSelector = ':lang(' + lang + ')';
+                                       declarations = getDeclarations( 
variantizeFileName( moreLangs[ lang ], variantName ) );
+                                       rules[ direction ].push(
+                                               selector.replace( /,|$/g, 
langSelector + '$&' ) +
+                                               ' {\n\t' + declarations + '\n}'
+                                       );
+
+                                       variantSvg = originalSvg[ 'lang-' + 
lang ].replace(
+                                               /<svg[^>]*>/, '$&<style>* { 
fill: ' + variant.getColor() + ' }</style>'
+                                       );
+
+                                       if ( originalSvg[ 'lang-' + lang ] === 
variantSvg ) {
+                                               uncolorizableImages.push( 
moreLangs[ lang ] );
+                                               continue;
+                                       }
+
+                                       destinationFilePath = path.join(
+                                               destinationPath,
+                                               variantizeFileName( moreLangs[ 
lang ], variantName )
+                                       );
+                                       files[ destinationFilePath ] = 
variantSvg;
+                               }
                        }
                } );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I47704bf9b643ef6e65f5bc138678439a55090773
Gerrit-PatchSet: 4
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to