laravel-localization
laravel-localization copied to clipboard
In AppServiceProvider can't get result
Describe the bug Visit my http://example.org The AppServiceProvider and welcome.blade.php have different result.
In AppServiceProvider
echo '<pre>'.print_r(app()->getLocale(), true).'</pre>';
echo '<pre>'.print_r(app()->currentLocale(), true).'</pre>';
echo '<pre>'.print_r(LaravelLocalization::getCurrentLocaleRegional(), true).'</pre>';
echo '<pre>'.print_r(LaravelLocalization::getCurrentLocale(), true).'</pre>';
echo '<pre>'.print_r(LaravelLocalization::getCurrentLocaleName(), true).'</pre>';
echo '<pre>'.print_r(LaravelLocalization::getCurrentLocaleNative(), true).'</pre>';
Result: zh_Hant zh_Hant zh_TW zh_Hant Chinese (Traditional) 繁體中文
In welcome.blade.php:
{{ app()->getLocale() }}<BR>
{{ app()->currentLocale() }}<BR>
{{ LaravelLocalization::getCurrentLocaleRegional() }}<BR>
{{ LaravelLocalization::getCurrentLocaleName() }}<BR>
{{ LaravelLocalization::getCurrentLocaleNative() }}<BR>
{{ LaravelLocalization::getCurrentLocaleRegional() }}<BR>
Result: en en English English en_GB
This is the same page. I can't find what went wrong.
To Reproduce Steps to reproduce the behavior:
- create laravel project
- install mcamara/laravel-localization
- edit the Kernel.php, web.php
- edit the AppServiceProvider.php and dashboard.blade.php
This is en page, why shows zh_TW ?
config\laravellocalization.php
'supportedLocales' => [
'en' => ['name' => 'English', 'script' => 'Latn', 'native' => 'English', 'regional' => 'en_GB'],
'zh_Hant' => ['name' => 'Chinese (Traditional)', 'script' => 'Hant', 'native' => '繁體中文', 'regional' => 'zh_TW'],
'zh_Hans' => ['name' => 'Chinese (Simplified)', 'script' => 'Hans', 'native' => '简体中文', 'regional' => 'zh_CN'],
...
]
'localesMapping' => [
'en' => 'en',
'zh_Hant' => 'zh-Hant', //Taiwan
'zh_Hans' => 'zh-Hans', //China
],
The zh_Hant is in the middle of the supportedLocales, why zh_Hant ?