Albert221 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402391 )

Change subject: Make charts, placeholder and summary translatable
......................................................................

Make charts, placeholder and summary translatable

Bug: T171636
Change-Id: Ib296d9065f58df1c995a9aea305398b208ab70fb
---
M i18n/en.json
M i18n/qqq.json
M index.html
M wikibase/queryService/ui/ResultView.js
M wikibase/queryService/ui/editor/Editor.js
5 files changed, 101 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/91/402391/1

diff --git a/i18n/en.json b/i18n/en.json
index b0eebff..ce77a6b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -54,10 +54,25 @@
     "wdqs-app-shorturl-page-title": "Short URL to this page",
     "wdqs-app-editor-placeholder": "(Input a SPARQL query or choose a query 
example)",
     "wdqs-app-editor-addprefixes": "Add Standard Prefixes",
+    "wdqs-app-resultbrowser-response-summary": "$1 
{{plural:$1|result|results}} in $2 ms",
     "wdqs-app-resultbrowser-stabilize": "Stabilize network",
     "wdqs-app-resultbrowser-hierarchical-lr": "Hierarchical layout left to 
right",
     "wdqs-app-resultbrowser-hierarchical-ud": "Hierarchical layout up to down",
     "wdqs-app-resultbrowser-hierarchical-rl": "Hierarchical layout right to 
left",
+    "wdqs-app-resultbrowser-table": "Table",
+    "wdqs-app-resultbrowser-image-grid": "Image grid",
+    "wdqs-app-resultbrowser-graph-builder": "Graph builder",
+    "wdqs-app-resultbrowser-map": "Map",
+    "wdqs-app-resultbrowser-line-chart": "Line chart",
+    "wdqs-app-resultbrowser-bar-chart": "Bar chart",
+    "wdqs-app-resultbrowser-scatter-chart": "Scatter chart",
+    "wdqs-app-resultbrowser-area-chart": "Area chart",
+    "wdqs-app-resultbrowser-bubble-chart": "Bubble chart",
+    "wdqs-app-resultbrowser-tree-map": "Tree map",
+    "wdqs-app-resultbrowser-tree": "Tree",
+    "wdqs-app-resultbrowser-timeline": "Timeline",
+    "wdqs-app-resultbrowser-dimensions": "Dimensions",
+    "wdqs-app-resultbrowser-graph": "Graph",
     "wdqs-app-toast-leave-fullscreen": "Press [esc] to leave fullscreen",
     "wdqs-dialog-examples-preview-query": "Preview query",
     "wdqs-dialog-examples-preview-result": "Preview result",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 56247e2..24aa70f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -56,10 +56,25 @@
        "wdqs-app-shorturl-page-title": "Title of link message on the left side 
of the editor",
        "wdqs-app-editor-placeholder": "Placeholder message in editor box",
        "wdqs-app-editor-addprefixes": "Button message in the prefix menu",
+       "wdqs-app-resultbrowser-response-summary": "Text summarizing query 
result count and time. Parameters:\n* $1 - result count\n* $2 - query time",
        "wdqs-app-resultbrowser-stabilize": "Button message in graph browser 
toolbar",
        "wdqs-app-resultbrowser-hierarchical-lr": "Button message in graph 
browser toolbar",
        "wdqs-app-resultbrowser-hierarchical-ud": "Button message in graph 
browser toolbar",
        "wdqs-app-resultbrowser-hierarchical-rl": "Button message in graph 
browser toolbar",
+       "wdqs-app-resultbrowser-table": "Label of Table",
+       "wdqs-app-resultbrowser-image-grid": "Label of Image grid",
+       "wdqs-app-resultbrowser-graph-builder": "Label of Graph builder",
+       "wdqs-app-resultbrowser-map": "Label of Map",
+       "wdqs-app-resultbrowser-line-chart": "Label of Line chart",
+       "wdqs-app-resultbrowser-bar-chart": "Label of Bar chart",
+       "wdqs-app-resultbrowser-scatter-chart": "Label of Scatter chart",
+       "wdqs-app-resultbrowser-area-chart": "Label of Area chart",
+       "wdqs-app-resultbrowser-bubble-chart": "Label of Bubble chart",
+       "wdqs-app-resultbrowser-tree-map": "Label of Tree map",
+       "wdqs-app-resultbrowser-tree": "Label of Tree",
+       "wdqs-app-resultbrowser-timeline": "Label of Timeline",
+       "wdqs-app-resultbrowser-dimensions": "Label of Dimensions",
+       "wdqs-app-resultbrowser-graph": "Label of Graph",
        "wdqs-app-toast-leave-fullscreen": "Explaination how to exit 
fullscreen",
        "wdqs-dialog-examples-preview-query": "Label to preview query in 
example dialog",
        "wdqs-dialog-examples-preview-result": "Label to preview result in 
example dialog",
diff --git a/index.html b/index.html
index 1684e15..752ee91 100644
--- a/index.html
+++ b/index.html
@@ -209,7 +209,8 @@
                                                <ul class="nav navbar-nav 
navbar-right">
                                                        <li class="navbar-text">
                                                                <span 
class="query-total">
-                                                               <span 
class="label label-default"><span id="total-results"></span> Results in <span 
id="query-time"></span> ms </span></span> &nbsp;
+                                                                       <span 
class="label label-default" id="response-summary"></span>
+                                                               </span> &nbsp;
                                                        </li>
                                                        <li>
                                                                <a class="btn" 
data-toggle="modal" data-target="#CodeExamples" 
data-i18n="[title]wdqs-app-button-code-title">
diff --git a/wikibase/queryService/ui/ResultView.js 
b/wikibase/queryService/ui/ResultView.js
index 326a32e..31b75d4 100644
--- a/wikibase/queryService/ui/ResultView.js
+++ b/wikibase/queryService/ui/ResultView.js
@@ -74,98 +74,98 @@
        SELF.prototype._resultBrowsers = {
                Table: {
                        icon: 'glyphicon-th-list',
-                       label: 'Table',
+                       label: [ 'wdqs-app-resultbrowser-table', 'Table' ],
                        class: 'TableResultBrowser',
                        object: null,
                        $element: null
                },
                ImageGrid: {
                        icon: 'glyphicon-picture',
-                       label: 'Image Grid',
+                       label: [ 'wdqs-app-resultbrowser-image-grid', 'Image 
grid' ],
                        class: 'ImageResultBrowser',
                        object: null,
                        $element: null
                },
                Polestar: {
                        icon: 'fa-certificate',
-                       label: 'Graph builder',
+                       label: [ 'wdqs-app-resultbrowser-graph-builder', 'Graph 
builder' ],
                        class: 'PolestarResultBrowser',
                        object: null,
                        $element: null
                },
                Map: {
                        icon: 'glyphicon-map-marker',
-                       label: 'Map',
+                       label: [ 'wdqs-app-resultbrowser-map', 'Map' ],
                        class: 'CoordinateResultBrowser',
                        object: null,
                        $element: null
                },
                LineChart: {
                        icon: 'fa-line-chart',
-                       label: 'Line Chart',
+                       label: [ 'wdqs-app-resultbrowser-line-chart', 'Line 
chart' ],
                        class: 'LineChartResultBrowser',
                        object: null,
                        $element: null
                },
                BarChart: {
                        icon: 'fa-bar-chart',
-                       label: 'Bar Chart',
+                       label: [ 'wdqs-app-resultbrowser-bar-chart', 'Bar 
chart' ],
                        class: 'BarChartResultBrowser',
                        object: null,
                        $element: null
                },
                ScatterChart: {
                        icon: 'fa-braille',
-                       label: 'Scatter Chart',
+                       label: [ 'wdqs-app-resultbrowser-scatter-chart', 
'Scatter chart' ],
                        class: 'ScatterChartResultBrowser',
                        object: null,
                        $element: null
                },
                AreaChart: {
                        icon: 'fa-area-chart',
-                       label: 'Area Chart',
+                       label: [ 'wdqs-app-resultbrowser-area-chart', 'Area 
chart' ],
                        class: 'AreaChartResultBrowser',
                        object: null,
                        $element: null
                },
                BubbleChart: {
                        icon: 'glyphicon-tint',
-                       label: 'Bubble Chart',
+                       label: [ 'wdqs-app-resultbrowser-bubble-chart', 'Bubble 
chart' ],
                        class: 'BubbleChartResultBrowser',
                        object: null,
                        $element: null
                },
                TreeMap: {
                        icon: 'glyphicon-th',
-                       label: 'Tree Map',
+                       label: [ 'wdqs-app-resultbrowser-tree-map', 'Tree map' 
],
                        class: 'TreeMapResultBrowser',
                        object: null,
                        $element: null
                },
                Tree: {
                        icon: 'fa-tree',
-                       label: 'Tree',
+                       label: [ 'wdqs-app-resultbrowser-tree', 'Tree' ],
                        class: 'TreeResultBrowser',
                        object: null,
                        $element: null
                },
                Timeline: {
                        icon: 'glyphicon-calendar',
-                       label: 'Timeline',
+                       label: [ 'wdqs-app-resultbrowser-timeline', 'Timeline' 
],
                        class: 'TimelineResultBrowser',
                        object: null,
                        $element: null
                },
                Dimensions: {
                        icon: 'glyphicon-random',
-                       label: 'Dimensions',
+                       label: [ 'wdqs-app-resultbrowser-dimensions', 
'Dimensions' ],
                        class: 'MultiDimensionResultBrowser',
                        object: null,
                        $element: null
                },
                Graph: {
                        icon: 'glyphicon-retweet',
-                       label: 'Graph',
+                       label: [ 'wdqs-app-resultbrowser-graph', 'Graph' ],
                        class: 'GraphResultBrowser',
                        object: null,
                        $element: null
@@ -195,7 +195,22 @@
 
                this._sparqlQuery = this._query = new 
wikibase.queryService.ui.queryHelper.SparqlQuery();
 
+               this._internationalizeCharts();
+
                this._initResultBrowserMenu();
+       };
+
+       /**
+        * @private
+        */
+       SELF.prototype._internationalizeCharts = function() {
+               var that = this;
+               $.each( this._resultBrowsers, function( key, chart ) {
+                       var i18nKey = chart.label[0],
+                               fallback = chart.label[1];
+
+                       chart.label = that._i18n( i18nKey, fallback );
+               } );
        };
 
        /**
@@ -323,8 +338,13 @@
        SELF.prototype._handleQueryResult = function() {
                var api = this._sparqlApi;
 
-               $( '#total-results' ).text( api.getResultLength() );
-               $( '#query-time' ).text( api.getExecutionTime() );
+               $( '#response-summary' ).text(
+                       this._i18n(
+                               'wdqs-app-resultbrowser-response-summary',
+                               '$1 results in $2 ms',
+                               [ api.getResultLength(), api.getExecutionTime() 
]
+                       )
+               );
                $( '.result' ).show();
 
                $( '#execute-button' ).prop( 'disabled', false );
@@ -488,6 +508,32 @@
                this._trackingApi.track( this.trackingNamespace + metricName, 
value, valueType );
        };
 
+       /**
+        * @private
+        */
+       SELF.prototype._i18n = function( key, message, args ) {
+               var i18nMessage = null;
+
+               if ( $.i18n ) {
+                       i18nMessage = $.i18n.apply( $, [ key ].concat( args || 
[] ) );
+                       if ( i18nMessage !== key ) {
+                               return i18nMessage;
+                       }
+               }
+
+               i18nMessage = message;
+               if ( args ) {
+                       $.each( args, function( index, arg ) {
+                               i18nMessage = i18nMessage.replace(
+                                       new RegExp( '\\$' + ( index + 1 ), 'g' 
),
+                                       arg
+                               );
+                       } );
+               }
+
+               return i18nMessage;
+       };
+
        return SELF;
 
 }( jQuery, window ) );
diff --git a/wikibase/queryService/ui/editor/Editor.js 
b/wikibase/queryService/ui/editor/Editor.js
index 912a30d..0fc9822 100644
--- a/wikibase/queryService/ui/editor/Editor.js
+++ b/wikibase/queryService/ui/editor/Editor.js
@@ -99,6 +99,11 @@
                var self = this;
 
                this._editor = CodeMirror.fromTextArea( element, 
CODEMIRROR_DEFAULTS );
+
+               setTimeout( function() {
+                       $( '.CodeMirror-placeholder' ).text( $( '.queryEditor' 
).prop( 'placeholder' ) );
+               }, 1000 );
+
                this._editor.on( 'change', function( editor, changeObj ) {
                        if ( self.getValue() !== '' ) {
                                self.storeValue( self.getValue() );
@@ -109,6 +114,8 @@
                                        closeCharacters: /[\s]/
                                } );
                        }
+
+                       $( '.CodeMirror-placeholder' ).text( $( '.queryEditor' 
).prop( 'placeholder' ) );
                } );
                this._editor.focus();
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib296d9065f58df1c995a9aea305398b208ab70fb
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Albert221 <[email protected]>

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

Reply via email to