Skip to content

Conversation

@markconnellypro
Copy link
Contributor

@markconnellypro markconnellypro commented Jan 15, 2026

Description

The documentation currently states that:

The system is smart enough to fall back to more generic language codes if an exact match cannot be found. If the locale code was set to en-US and we only have language files set up for en then those will be used since nothing exists for the more specific en-US.

This appears to be built in when Content Negotiation is used, but not when the setLocale function is called in IncomingRequest. This pull request changes this function so that it also tries the generic language code before setting the default locale as the locale. This avoids situations where, for example, "fr" is a supportedLocale, but, when "fr-FR" is passed to setLocale, it ignores this and picks a different default locale because "fr-FR" is not an exact match to "fr".

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Enhanced locale validation to check for language-only locales before falling back to the default.
Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please add a changelog entry, under the "Bugs" section, here: https://github.com/codeigniter4/CodeIgniter4/blob/develop/user_guide_src/source/changelogs/v4.6.5.rst.

Please follow the convention used in previous files.

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

Successfully merging this pull request may close these issues.

2 participants