You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user_guide_src/source/changelogs/v4.6.0.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -242,9 +242,9 @@ Routing
242
242
Negotiator
243
243
==========
244
244
245
-
- Added a feature flag ``Feature::$looseLocaleNegotiation`` fix simple locale comparison.
245
+
- Added a feature flag ``Feature::$strictLocaleNegotiation`` to enable strict locale comparision.
246
246
Previously, response with language headers ``Accept-language: en-US,en-GB;q=0.9`` returned the first allowed language ``en`` could instead of the exact language ``en-US`` or ``en-GB``.
247
-
Set the value to ``false`` to be able to get ``en-*``
247
+
Set the value to ``true`` to enable comparison not only by language code ('en' - ISO 639-1) but also by regional code ('en-US' - ISO 639-1 plus ISO 3166-1 alpha).
Copy file name to clipboardExpand all lines: user_guide_src/source/incoming/content_negotiation.rst
+49-2Lines changed: 49 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,10 +102,57 @@ and German you would do something like:
102
102
In this example, 'en' would be returned as the current language. If no match is found, it will return the first element
103
103
in the ``$supported`` array, so that should always be the preferred language.
104
104
105
+
Strict Locale Negotiation
106
+
-------------------------
107
+
105
108
.. versionadded:: 4.6.0
106
109
107
-
Disabling the ``Config\Feature::$looseLocaleNegotiation`` value allows you to strictly search for the requested language from the specified territory (``en-*``).
108
-
In the case of a non-strict search, the language may be limited only by the country ``en``. Don't forget to create files for the ``en-*`` locale if you need a translation.
110
+
By default, locale is determined on a lossy comparison basis. So only the first part of the locale string is taken
111
+
into account (language). This is usually sufficient. But sometimes we want to be able to distinguish between regional versions such as
112
+
``en-US`` and ``en-GB`` to serve different content.
113
+
114
+
For such cases, we have introduced a new setting that can be enabled via ``Config\Feature::$strictLocaleNegotiation``. This will ensure
115
+
that the strict comparison will be made in the first place.
116
+
117
+
.. note::
118
+
119
+
CodeIgniter comes with translations only for primary language tags ('en', 'fr', etc.). So if you enable this feature and your
120
+
settings in ``Config\App::$supportedLocales`` include regional language tags ('en-US', 'fr-FR', etc.), then keep in mind that
121
+
if you have your own translation files, you **must also change** the folder names for CodeIgniter's translation files to match
122
+
what you put in the ``$supportedLocales`` array.
123
+
124
+
Now let's consider the below example. The browser's preferred language will be set as this::
125
+
126
+
GET /foo HTTP/1.1
127
+
Accept-Language: fr; q=1.0, en-GB; q=0.5
128
+
129
+
In this example, the browser would prefer French, with a second choice of English (United Kingdom). Your website on another hand will
0 commit comments