Skip to content

Commit 3cb3839

Browse files
committed
docs: add about missing Language locale
1 parent 4f2de95 commit 3cb3839

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

user_guide_src/source/outgoing/localization.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,14 @@ file:
9292
Setting the Current Locale
9393
==========================
9494

95-
If you want to set the locale directly, you may use
96-
``IncomingRequest::setLocale(string $locale)``.
95+
IncomingRequest Locale
96+
----------------------
97+
98+
If you want to set the locale directly, you may use the ``setLocale()`` method in
99+
the :doc:`../incoming/incomingrequest`:
100+
101+
.. literalinclude:: localization/020.php
102+
:lines: 2-
97103

98104
Before setting the locale, you must set valid locales. Because any attempt to
99105
set a locale that are not valid will result in
@@ -108,6 +114,18 @@ in **app/Config/App.php**:
108114
set (and reset) valid locales. Use it if you want to change the valid locales
109115
dynamically.
110116

117+
Language Locale
118+
---------------
119+
120+
The ``Language`` class used in the :php:func:`lang()` function also has the current
121+
locale. This is set to the ``IncommingRequest`` locale during instantiating.
122+
123+
If you want to change the locale after instantiating the language class, use the
124+
``Language::setLocale()`` method.
125+
126+
.. literalinclude:: localization/021.php
127+
:lines: 2-
128+
111129
Retrieving the Current Locale
112130
=============================
113131

@@ -218,10 +236,12 @@ Specifying Locale
218236
-----------------
219237

220238
To specify a different locale to be used when replacing parameters, you can pass the locale in as the
221-
third parameter to the ``lang()`` function.
239+
third parameter to the :php:func:`lang()` function.
222240

223241
.. literalinclude:: localization/016.php
224242

243+
If you want to change the current locale, see `Language Locale`_.
244+
225245
Nested Arrays
226246
-------------
227247

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
/** @var \CodeIgniter\HTTP\IncomingRequest $request */
4+
$request->setLocale('ja');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
/** @var \CodeIgniter\Language\Language $lang */
4+
$lang = service('language');
5+
$lang->setLocale('ja');

0 commit comments

Comments
 (0)