Skip to content

docs: fix localization.rst #5384

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

Merged
merged 4 commits into from
Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions user_guide_src/source/outgoing/localization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ supported language::
/app
/Language
/en
app.php
App.php
/fr
app.php
App.php

.. important:: Locale detection only works for web-based requests that use the IncomingRequest class.
Command-line requests will not have these features.
Expand Down Expand Up @@ -119,20 +119,16 @@ You might name it simply: **Errors.php**.

Within the file, you would return an array, where each element in the array has a language key and can have string to return::

'language_key' => 'The actual message to be shown.'
'languageKey' => 'The actual message to be shown.'

It also support nested definition::

'language_key' => [
'languageKey' => [
'nested' => [
'key' => 'The actual message to be shown.',
],
],

.. note:: It's good practice to use a common prefix for all messages in a given file to avoid collisions with
similarly named items in other files. For example, if you are creating error messages you might prefix them
with error\_

::

return [
Expand Down Expand Up @@ -174,9 +170,9 @@ You can pass an array of values to replace placeholders in the language string a

// The language file, Tests.php:
return [
"apples" => "I have {0, number} apples.",
"men" => "The top {1, number} men out-performed the remaining {0, number}",
"namedApples" => "I have {number_apples, number, integer} apples.",
'apples' => 'I have {0, number} apples.',
'men' => 'The top {1, number} men out-performed the remaining {0, number}',
'namedApples' => 'I have {number_apples, number, integer} apples.',
];

// Displays "I have 3 apples."
Expand All @@ -190,7 +186,7 @@ The first item in the placeholder corresponds to the index of the item in the ar
You can also use named keys to make it easier to keep things straight, if you'd like::

// Displays "I have 3 apples."
echo lang("Tests.namedApples", ['number_apples' => 3]);
echo lang('Tests.namedApples', ['number_apples' => 3]);

Obviously, you can do more than just number replacement. According to the
`official ICU docs <https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classMessageFormat.html#details>`_ for the underlying
Expand Down