laravel-localization icon indicating copy to clipboard operation
laravel-localization copied to clipboard

In AppServiceProvider can't get result

Open ronrun opened this issue 1 month ago • 0 comments

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:

  1. create laravel project
  2. install mcamara/laravel-localization
  3. edit the Kernel.php, web.php
  4. edit the AppServiceProvider.php and dashboard.blade.php

01

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 ?

ronrun avatar May 09 '24 08:05 ronrun