Skip to content
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

docs: improve Localization #9109

Merged
merged 13 commits into from
Aug 16, 2024
54 changes: 32 additions & 22 deletions user_guide_src/source/outgoing/localization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ CodeIgniter provides several tools to help you localize your application for dif
localization of an application is a complex subject, it's simple to swap out strings in your application
with different supported languages.

Language strings are stored in the **app/Language** directory, with a sub-directory for each
supported language::

app/
Language/
en/
App.php
fr/
App.php

.. important:: Locale detection only works for web-based requests that use the IncomingRequest class.
Command-line requests will not have these features.

Configuring the Locale
======================

Expand All @@ -52,10 +39,13 @@ directory existed at the **app/Language/en-US** directory then that would be use
Locale Detection
================

There are two methods supported to detect the correct locale during the request. The first is a "set and forget"
method that will automatically perform :doc:`content negotiation </incoming/content_negotiation>` for you to
determine the correct locale to use. The second method allows you to specify a segment in your routes that
will be used to set the locale.
.. important:: Locale detection only works for web-based requests that use the IncomingRequest class.
Command-line requests will not have these features.

There are two methods supported to detect the correct locale during the request.

1. `Content Negotiation`_: The first is a "set and forget" method that will automatically perform :doc:`content negotiation </incoming/content_negotiation>` for you to determine the correct locale to use.
2. `In Routes`_: The second method allows you to specify a segment in your routes that will be used to set the locale.

Should you ever need to set the locale directly, see `Setting the Current Locale`_.

Expand Down Expand Up @@ -139,6 +129,16 @@ Language Localization
Creating Language Files
=======================

Language strings are stored in the **app/Language** directory, with a sub-directory for each
supported language (locale)::

app/
Language/
en/
App.php
fr/
App.php

.. note:: The Language Files do not have namespaces.

Languages do not have any specific naming convention that are required. The file should be named logically to
Expand Down Expand Up @@ -231,8 +231,8 @@ Language Fallback
=================

If you have a set of messages for a given locale, for instance
**Language/en/app.php**, you can add language variants for that locale,
each in its own folder, for instance **Language/en-US/app.php**.
**Language/en/App.php**, you can add language variants for that locale,
each in its own folder, for instance **Language/en-US/App.php**.

You only need to provide values for those messages that would be
localized differently for that locale variant. Any missing message
Expand All @@ -246,10 +246,10 @@ So, if you are using the locale ``fr-CA``, then a localized
message will first be sought in the **Language/fr-CA** directory, then in
the **Language/fr** directory, and finally in the **Language/en** directory.

Message Translations
====================
System Message Translations
===========================

We have an "official" set of translations in their
We have an "official" set of the system message translations in their
`own repository <https://github.com/codeigniter4/translations>`_.

You could download that repository, and copy its **Language** folder
Expand All @@ -266,6 +266,16 @@ project:
The translated messages will be automatically picked
up because the translations folders get mapped appropriately.

Overriding System Message Translations
======================================

The framework provide `System Message Translations`_, and packages that you
installed may also provide the message translations.

If you want to override some language messages, create language files in the
**app/Language** directory. Then, return only the array you want to override
in the file.

.. _generating-translation-files-via-command:

Generating Translation Files via Command
Expand Down