Skip to content

Commit b1e0aac

Browse files
authored
Merge pull request #245 from contactashish13/issue-240
Issue with non-English text
2 parents ed204fd + 05bdb1e commit b1e0aac

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

classes/Visualizer/Module.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,20 @@ private function _getHTML( $rows ) {
323323
);
324324
}
325325

326+
/**
327+
* Returns the language of the locale.
328+
*
329+
* @access protected
330+
*/
331+
protected function get_language() {
332+
$locale = get_locale();
333+
if ( empty( $locale ) ) {
334+
return '';
335+
}
336+
$array = explode( '_', $locale );
337+
if ( count( $array ) < 2 ) {
338+
return '';
339+
}
340+
return reset( $array );
341+
}
326342
}

classes/Visualizer/Module/Admin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ public function renderLibraryPage() {
460460
$ajaxurl = admin_url( 'admin-ajax.php' );
461461
wp_localize_script(
462462
'visualizer-library', 'visualizer', array(
463+
'language' => $this->get_language(),
464+
'map_api_key' => get_option( 'visualizer-map-api-key' ),
463465
'charts' => $charts,
464466
'urls' => array(
465467
'base' => add_query_arg( 'vpage', false ),

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ private function _handleDataAndSettingsPage() {
336336
'charts' => array(
337337
'canvas' => $data,
338338
),
339+
'language' => $this->get_language(),
339340
'map_api_key' => get_option( 'visualizer-map-api-key' ),
340341
'ajax' => array(
341342
'url' => admin_url( 'admin-ajax.php' ),

classes/Visualizer/Module/Frontend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public function renderChart( $atts ) {
238238
wp_localize_script(
239239
'visualizer-render', 'visualizer', array(
240240
'charts' => $this->_charts,
241+
'language' => $this->get_language(),
241242
'map_api_key' => get_option( 'visualizer-map-api-key' ),
242243
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
243244
'i10n' => array(

classes/Visualizer/Source.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ protected function _normalizeData( $data ) {
222222
}
223223
break;
224224
case 'string':
225-
$data[ $i ] = utf8_encode( $data[ $i ] );
225+
// condition introduced for Issue with non-English text #240 where languages such as Hebrew get messed up.
226+
if ( function_exists( 'mb_detect_encoding' ) && mb_detect_encoding( $data[ $i ] ) !== 'UTF-8' ) {
227+
$data[ $i ] = utf8_encode( $data[ $i ] );
228+
}
226229
break;
227230
}
228231
}

js/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
}
223223
};
224224

225-
g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key});
225+
g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language});
226226
g.charts.setOnLoadCallback(function() {
227227
gv = g.visualization;
228228
v.render();

0 commit comments

Comments
 (0)