@@ -17,11 +17,11 @@ with different supported languages.
1717Language strings are stored in the **app/Language ** directory, with a sub-directory for each
1818supported language::
1919
20- / app
21- / Language
22- /en
20+ app/
21+ Language/
22+ en/
2323 App.php
24- /fr
24+ fr/
2525 App.php
2626
2727.. important :: Locale detection only works for web-based requests that use the IncomingRequest class.
@@ -30,7 +30,7 @@ supported language::
3030Configuring the Locale
3131======================
3232
33- Every site will have a default language/locale they operate in. This can be set in **Config/App.php **:
33+ Every site will have a default language/locale they operate in. This can be set in **app/ Config/App.php **:
3434
3535.. literalinclude :: localization/001.php
3636
@@ -40,9 +40,9 @@ language codes like en-US for American English, or fr-FR, for French/France. A m
4040to this can be found on the `W3C's site <https://www.w3.org/International/articles/language-tags/ >`_.
4141
4242The system is smart enough to fall back to more generic language codes if an exact match
43- cannot be found. If the locale code was set to ** en-US ** and we only have language files set up for ** en **
44- then those will be used since nothing exists for the more specific ** en-US ** . If, however, a language
45- directory existed at **app/Language/en-US ** then that would be used first.
43+ cannot be found. If the locale code was set to `` en-US `` and we only have language files set up for `` en ``
44+ then those will be used since nothing exists for the more specific `` en-US `` . If, however, a language
45+ directory existed at the **app/Language/en-US ** directory then that would be used first.
4646
4747Locale Detection
4848================
@@ -57,15 +57,15 @@ Should you ever need to set the locale directly you may use ``IncomingRequest::s
5757Content Negotiation
5858-------------------
5959
60- You can set up content negotiation to happen automatically by setting two additional settings in Config/App.
60+ You can set up content negotiation to happen automatically by setting two additional settings in ** app/ Config/App.php ** .
6161The first value tells the Request class that we do want to negotiate a locale, so simply set it to true:
6262
6363.. literalinclude :: localization/002.php
6464
6565Once this is enabled, the system will automatically negotiate the correct language based upon an array
6666of locales that you have defined in ``$supportLocales ``. If no match is found between the languages
6767that you support, and the requested language, the first item in $supportedLocales will be used. In
68- the following example, the ** en ** locale would be used if no match is found:
68+ the following example, the `` en `` locale would be used if no match is found:
6969
7070.. literalinclude :: localization/003.php
7171
@@ -80,7 +80,7 @@ segment will be your locale:
8080
8181.. literalinclude :: localization/004.php
8282
83- In this example, if the user tried to visit `` http://example.com/fr/books `` , then the locale would be
83+ In this example, if the user tried to visit ** http://example.com/fr/books ** , then the locale would be
8484set to ``fr ``, assuming it was configured as a valid locale.
8585
8686If the value doesn't match a valid locale as defined in ``$supportedLocales `` in **app/Config/App.php **, the default
8989
9090.. literalinclude :: localization/018.php
9191
92- .. note :: ``useSupportedLocalesOnly()`` can be used since v4.3.0.
92+ .. note :: The ``useSupportedLocalesOnly()`` method can be used since v4.3.0.
9393
9494Retrieving the Current Locale
9595=============================
@@ -110,6 +110,8 @@ Language Localization
110110Creating Language Files
111111=======================
112112
113+ .. note :: The Language Files do not have namespaces.
114+
113115Languages do not have any specific naming convention that are required. The file should be named logically to
114116describe the type of content it holds. For example, let's say you want to create a file containing error messages.
115117You might name it simply: **Errors.php **.
@@ -127,9 +129,9 @@ It also support nested definition:
127129Basic Usage
128130===========
129131
130- You can use the `` lang() ` ` helper function to retrieve text from any of the language files, by passing the
132+ You can use the :php:func: ` lang() ` helper function to retrieve text from any of the language files, by passing the
131133filename and the language key as the first parameter, separated by a period (.). For example, to load the
132- ``errorEmailMissing `` string from the `` Errors `` language file, you would do the following:
134+ ``errorEmailMissing `` string from the ** Errors.php ** language file, you would do the following:
133135
134136.. literalinclude :: localization/010.php
135137
@@ -183,7 +185,7 @@ Specifying Locale
183185-----------------
184186
185187To specify a different locale to be used when replacing parameters, you can pass the locale in as the
186- third parameter to the ``lang() `` method .
188+ third parameter to the ``lang() `` function .
187189
188190.. literalinclude :: localization/016.php
189191
@@ -198,8 +200,8 @@ Language Fallback
198200=================
199201
200202If you have a set of messages for a given locale, for instance
201- `` Language/en/app.php `` , you can add language variants for that locale,
202- each in its own folder, for instance `` Language/en-US/app.php `` .
203+ ** Language/en/app.php ** , you can add language variants for that locale,
204+ each in its own folder, for instance ** Language/en-US/app.php ** .
203205
204206You only need to provide values for those messages that would be
205207localized differently for that locale variant. Any missing message
@@ -210,19 +212,23 @@ in case new messages are added to the framework and you haven't had
210212a chance to translate them yet for your locale.
211213
212214So, if you are using the locale ``fr-CA ``, then a localized
213- message will first be sought in `` Language/fr/CA `` , then in
214- `` Language/fr `` , and finally in `` Language/en `` .
215+ message will first be sought in the ** Language/fr-CA ** directory , then in
216+ the ** Language/fr ** directory , and finally in the ** Language/en ** directory .
215217
216218Message Translations
217219====================
218220
219221We have an "official" set of translations in their
220222`own repository <https://github.com/codeigniter4/translations >`_.
221223
222- You could download that repository, and copy its ``Language `` folder
223- into your ``app ``. The incorporated translations will be automatically
224- picked up because the ``App `` namespace is mapped to your ``app `` folder.
224+ You could download that repository, and copy its **Language ** folder
225+ into your **app ** folder. The incorporated translations will be automatically
226+ picked up because the ``App `` namespace is mapped to your **app ** folder.
227+
228+ Alternately, a better practice would be to run the following command inside your
229+ project::
230+
231+ > composer require codeigniter4/translations
225232
226- Alternately, a better practice would be to ``composer require codeigniter4/translations ``
227- inside your project, and the translated messages will be automatically picked
233+ The translated messages will be automatically picked
228234up because the translations folders get mapped appropriately.
0 commit comments