Skip to content
Browse files

try harder for setting a UTF-8 locale

  • Loading branch information...
1 parent f0b6681 commit 773750b77dddaea61c760aca7fde84998723e3da @nicolas-grekas committed Oct 16, 2012
Showing with 14 additions and 4 deletions.
  1. +2 −3 bootstrapper.php
  2. +0 −1 core/boot/bootup.patchwork.php
  3. +12 −0 core/utf8/bootup.patchwork.php
View
5 bootstrapper.php
@@ -19,9 +19,9 @@
header('Content-Type: text/plain; charset=utf-8'); // Ease with early error messages
ini_set('html_errors', false); // "
ini_set('display_errors', true); // "
-defined('PATCHWORK_BOOTPATH') || define('PATCHWORK_BOOTPATH', '.');
+defined('PATCHWORK_BOOTPATH') or define('PATCHWORK_BOOTPATH', '.');
-PATCHWORK_BOOTPATH || die('Patchwork error: PATCHWORK_BOOTPATH is empty');
+PATCHWORK_BOOTPATH or die('Patchwork error: PATCHWORK_BOOTPATH is empty');
if (file_exists(PATCHWORK_BOOTPATH . '/.patchwork.php'))
return require PATCHWORK_BOOTPATH . '/.patchwork.php';
@@ -30,7 +30,6 @@
die("Patchwork error: PHP 5.2.0 or higher is required");
error_reporting(E_ALL | E_STRICT);
-setlocale(LC_ALL, 'C.UTF-8', 'C');
require dirname(__FILE__) . '/core/boot/class/Patchwork/Bootstrapper/Manager.php';
require dirname(__FILE__) . '/core/boot/class/Patchwork/Bootstrapper.php';
View
1 core/boot/bootup.patchwork.php
@@ -19,7 +19,6 @@
ini_set('html_errors', false);
ini_set('display_errors', true);
error_reporting(/*<*/E_ALL | E_STRICT/*>*/);
-setlocale(LC_ALL, /*<*/setlocale(LC_ALL, 0)/*>*/);
// spl_autoload() evades code preprocessing, do not use it
View
12 core/utf8/bootup.patchwork.php
@@ -27,6 +27,18 @@
p\Shim(utf8_decode, s\Xml::utf8_to_cp1252, $s);
+// Try to set a UTF-8 compatible locale
+
+/**/$a = setlocale(LC_CTYPE, 'C.UTF-8', 'en_US.UTF-8', 'en_US.utf8', 0);
+
+setlocale(LC_ALL, /*<*/setlocale(LC_CTYPE, 'C.UTF-8', 'C')/*>*/);
+
+/**/if ('C.UTF-8' !== setlocale(LC_CTYPE, 0) && preg_match('/\.UTF-?8$/i', $a))
+/**/{
+ setlocale(LC_CTYPE, /*<*/setlocale(LC_CTYPE, $a)/*>*/);
+/**/}
+
+
// Locale sensitivity breaks UTF-8
/**/if ('' === basename('§'))

0 comments on commit 773750b

Please sign in to comment.
Something went wrong with that request. Please try again.