Skip to content

Commit ffb37c1

Browse files
Merge pull request #257 from contactashish13/issue-240
Issue with non-English text
2 parents d71c4e5 + c612a55 commit ffb37c1

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

classes/Visualizer/Source.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ protected function _normalizeData( $data ) {
222222
}
223223
break;
224224
case 'string':
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-
}
225+
$data[ $i ] = $this->toUTF8( $data[ $i ] );
229226
break;
230227
}
231228
}
@@ -234,4 +231,21 @@ protected function _normalizeData( $data ) {
234231
return $data;
235232
}
236233

234+
235+
/**
236+
* Converts values to UTF8, if required.
237+
*
238+
* @access protected
239+
*
240+
* @param string $datum The data to convert.
241+
*
242+
* @return string The converted data.
243+
*/
244+
protected final function toUTF8( $datum ) {
245+
if ( ! function_exists( 'mb_detect_encoding' ) || mb_detect_encoding( $datum ) !== 'ASCII' ) {
246+
$datum = \ForceUTF8\Encoding::toUTF8( $datum );
247+
}
248+
return $datum;
249+
}
250+
237251
}

classes/Visualizer/Source/Csv.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ private function _fetchSeries( &$handle ) {
8383

8484
for ( $i = 0, $len = count( $labels ); $i < $len; $i++ ) {
8585
$default_type = $i == 0 ? 'string' : 'number';
86+
87+
$labels[ $i ] = $this->toUTF8( $labels[ $i ] );
88+
8689
$this->_series[] = array(
8790
'label' => $labels[ $i ],
8891
'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type,

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"require": {
2424
"codeinwp/themeisle-sdk": "master",
2525
"xrstf/composer-php52": "^1.0.20",
26-
"PHPOffice/PHPExcel": "^1.8.1"
26+
"PHPOffice/PHPExcel": "^1.8.1",
27+
"neitanod/forceutf8": "~2.0"
2728
},
2829
"autoload": {
2930
"files": [

0 commit comments

Comments
 (0)