Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In AppServiceProvider can't get result #903

Open
ronrun opened this issue May 9, 2024 · 0 comments
Open

In AppServiceProvider can't get result #903

ronrun opened this issue May 9, 2024 · 0 comments

Comments

@ronrun
Copy link

ronrun commented May 9, 2024

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant