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

Bug: IncomingRequest::setLocale() #3640

Closed
nicojmb opened this issue Sep 13, 2020 · 2 comments
Closed

Bug: IncomingRequest::setLocale() #3640

nicojmb opened this issue Sep 13, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@nicojmb
Copy link

nicojmb commented Sep 13, 2020

Describe the bug
I've a LanguageFilter wiht method "before" to check session value and set current languange with method setLanguage($locale) in the codigniter request classs.

In debug toolbar the the laguage is correct but translations show incorrect language (when i use lang() always return default language translation).

the problem only happens when i've an lang() function call before the request()->setLocale($language) and static service language not update when run setLocale($locale) and return next translation with default locale.

image

image

The translation files are correct, if i change default language to english, showme "logout" twice :(

image

If i comment the first lang() then works as expected.

CodeIgniter 4 version
4.0.4

Affected module(s)
Language Helper
Language Service

Expected behavior, and steps to reproduce if appropriate
lang() function get correct translation after "setLocale" function.

Context

  • OS: Centos
  • Web server: Nginx
  • PHP version: 7.4.10
@nicojmb nicojmb added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 13, 2020
@michalsn
Copy link
Member

This is not a bug. When we call lang() function for the first time we simply initialize the shared language service. The next call to lang() operates on the same instance as before so that's why there is no change - despite changing the locale for the request.

You should use service('language')->setLocale($lang) instead.

@nicojmb
Copy link
Author

nicojmb commented Sep 14, 2020

Great, i try and works, boy also needs to call "service('request')->setLocale($lang);" to update request current language if not the debug toolbar showme incorrect language buy translations works.

My code now looks like this:

service('language')->setLocale($lang);
service('request')->setLocale($lang);

And works as spected, thankyou so much @michalsn

@michalsn michalsn changed the title Bug: Bug: IncomingRequest::setLocale() Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants