Skip to content

Commit

Permalink
Merge pull request codeigniter4#8836 from kenjis/docs-improve-lang
Browse files Browse the repository at this point in the history
docs: improve lang()
  • Loading branch information
kenjis authored Apr 30, 2024
2 parents ff75ed3 + 0153a89 commit 8b0c99b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 6 additions & 4 deletions user_guide_src/source/general/common_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ Service Accessors

.. php:function:: lang($line[, $args[, $locale]])
:param string $line: The line of text to retrieve
:param string $line: The language filename and the key of the text to retrieve.
:param array $args: An array of data to substitute for placeholders.
:param string $locale: Specify a different locale to be used instead of default one.
:param string $locale: Specify a different locale to be used instead of the current locale.
:returns: The text in the language file
:rtype: list<string>|string

Retrieves a locale-specific file based on an alias string.
Retrieves text from the language files.

For more information, see the :doc:`Localization </outgoing/localization>` page.
For more information, see the :ref:`language-localization`.

.. php:function:: model($name[, $getShared = true[, &$conn = null]])
Expand Down
10 changes: 7 additions & 3 deletions user_guide_src/source/outgoing/localization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ Alternatively, you can use the :doc:`Services class </concepts/services>` to ret

.. literalinclude:: localization/006.php

.. _language-localization:

*********************
Language Localization
*********************
Expand Down Expand Up @@ -157,8 +159,10 @@ Basic Usage
===========

You can use the :php:func:`lang()` helper function to retrieve text from any of the language files, by passing the
filename and the language key as the first parameter, separated by a period (.). For example, to load the
``errorEmailMissing`` string from the **Errors.php** language file, you would do the following:
filename and the language key as the first parameter, separated by a period (``.``).

For example, to load the ``errorEmailMissing`` string from the **Errors.php**
language file, you would do the following:

.. literalinclude:: localization/010.php

Expand All @@ -167,7 +171,7 @@ For nested definition, you would do the following:
.. literalinclude:: localization/011.php

If the requested language key doesn't exist in the file for the current locale, the string will be passed
back, unchanged. In this example, it would return 'Errors.errorEmailMissing' or 'Errors.nested.error.message' if it didn't exist.
back, unchanged. In this example, it would return ``Errors.errorEmailMissing`` or ``Errors.nested.error.message`` if it didn't exist.

Replacing Parameters
--------------------
Expand Down

0 comments on commit 8b0c99b

Please sign in to comment.