Skip to content
Snippets Groups Projects
Commit 1e91b86e authored by Peter Rotich's avatar Peter Rotich
Browse files

Move CSV delimiter detection to i18n

parent af9a288f
No related branches found
No related tags found
No related merge requests found
......@@ -372,17 +372,7 @@ class CsvResultsExporter extends ResultSetExporter {
if (!$this->output)
$this->output = fopen('php://output', 'w');
// Detect delimeter from the current locale settings. For locales
// which use comma (,) as the decimal separator, the semicolon (;)
// should be used as the field separator
$delimiter = ',';
if (class_exists('NumberFormatter')) {
$nf = NumberFormatter::create(Internationalization::getCurrentLocale(),
NumberFormatter::DECIMAL);
$s = $nf->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
if ($s == ',')
$delimiter = ';';
}
$delimiter = Internationalization::getCSVDelimiter();
// Output a UTF-8 BOM (byte order mark)
fputs($this->output, chr(0xEF) . chr(0xBB) . chr(0xBF));
......
......@@ -401,6 +401,30 @@ class Internationalization {
return $locale;
}
static function getCSVDelimiter($locale='') {
if (!$locale) // Prefer browser settings
$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
// Detect delimeter from the current locale settings. For locales
// which use comma (,) as the decimal separator, the semicolon (;)
// should be used as the field separator
$delimiter = ',';
if (class_exists('NumberFormatter')) {
$nf = NumberFormatter::create($locale ?: self::getCurrentLocale(),
NumberFormatter::DECIMAL);
$s = $nf->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
if ($s == ',')
$delimiter = ';';
} else {
$info = localeconv();
if ($info && $info['decimal_point'] == ',')
$delimiter = ';';
}
return $delimiter;
}
// getIntDateFormatter($options)
//
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment