From 8208d44466f32f00a737c529f7dafbf16e85d998 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 8 Jan 2017 16:55:02 +0100 Subject: [PATCH] =?UTF-8?q?This=20should=20fix=20locale=20information=20fo?= =?UTF-8?q?r=20specific=20languages.=20It=E2=80=99s=20not=20perfect=20yet?= =?UTF-8?q?=20though.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Middleware/Range.php | 36 +++++++++++++++++++++++------ public/js/ff/firefly.js | 4 ++-- resources/views/layout/default.twig | 1 + 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 5e3e119098..6b9b250f39 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -23,7 +23,6 @@ use Illuminate\Contracts\Auth\Guard; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Navigation; -use NumberFormatter; use Preferences; use Session; use View; @@ -111,20 +110,43 @@ class Range $monthAndDayFormat = (string)trans('config.month_and_day'); $dateTimeFormat = (string)trans('config.date_time'); $defaultCurrency = Amount::getDefaultCurrency(); + $localeconv = localeconv(); - // change localeconv to a new array: - $numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY); - $localeconv = [ - 'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)), - 'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)), - 'frac_digits' => $defaultCurrency->decimal_places, + // decimal places is overruled by TransactionCurrency + $localeconv['frac_digits'] = $defaultCurrency->decimal_places; + $positiveSpace = ' '; + $negativeSpace = ' '; + // positive number: + if (!$localeconv['p_sep_by_space']) { + $positiveSpace = ''; + } + // negative number: + if (!$localeconv['n_sep_by_space']) { + $negativeSpace = ''; + } + // by default, put symbols before: + $accounting = [ + 'pos' => '%s' . $positiveSpace . '%v', + 'neg' => '%s' . $negativeSpace . '-%v', + 'zero' => '%s' . $positiveSpace . '%v', ]; + + // but might be after: + if (!$localeconv['n_cs_precedes']) { + $accounting['neg'] = '-%v' . $negativeSpace . '%s'; + } + if (!$localeconv['p_cs_precedes']) { + $accounting['pos'] = '%v' . $negativeSpace . '%s'; + $accounting['zero'] = '%v' . $negativeSpace . '%s'; + } + View::share('monthFormat', $monthFormat); View::share('monthAndDayFormat', $monthAndDayFormat); View::share('dateTimeFormat', $dateTimeFormat); View::share('language', $lang); View::share('localeconv', $localeconv); View::share('defaultCurrency', $defaultCurrency); + View::share('accountingConfig', $accounting); } /** diff --git a/public/js/ff/firefly.js b/public/js/ff/firefly.js index 82a22f16c1..4f33376896 100644 --- a/public/js/ff/firefly.js +++ b/public/js/ff/firefly.js @@ -7,7 +7,7 @@ * * See the LICENSE file for details. */ -/** global: moment, dateRangeConfig, accounting, currencySymbol, mon_decimal_point, frac_digits, showFullList, showOnlyTop, mon_thousands_sep */ +/** global: moment, accountingConfig, dateRangeConfig, accounting, currencySymbol, mon_decimal_point, frac_digits, showFullList, showOnlyTop, mon_thousands_sep */ $(function () { @@ -112,7 +112,7 @@ function currencySelect(e) { accounting.settings = { currency: { symbol: currencySymbol, // default currency symbol is '$' - format: "%s %v", // controls output: %s = symbol, %v = value/number (can be object: see below) + format: accountingConfig, // controls output: %s = symbol, %v = value/number (can be object: see below) decimal: mon_decimal_point, // decimal point separator thousand: mon_thousands_sep, // thousands separator precision: frac_digits // decimal places diff --git a/resources/views/layout/default.twig b/resources/views/layout/default.twig index 48b28f506e..85b8f95e3b 100644 --- a/resources/views/layout/default.twig +++ b/resources/views/layout/default.twig @@ -208,6 +208,7 @@ var noDataForChart = '{{ trans('firefly.no_data_for_chart')|escape }}'; var showFullList = '{{ trans('firefly.show_full_list') }}'; var showOnlyTop = '{{ trans('firefly.show_only_top',{number:listLength}) }}'; + var accountingConfig = {{ accountingConfig|json_encode|raw }};