Introduction

WebForms.PHP engine has built-in mechanisms for localization.

There are two levels of localization: global and local.

Global level applies to the entire site. Powers of the local level apply only to a specific page.

For localization resource files used in JSON format.

The resource file names must contain the code of culture (language). Culture code - this is the standard two-letter language code. For example: ru, en. If the name of the resource file does not contain the code of culture, it's such a file is considered the default file.

Loading resource files in the following sequence: global.json, global resource of the current culture, default local resource file and local file of the current culture. The upper keys can overwrite the key values of the lower level.

The values of key resources may contain keys other resources, but no deeper than one level.

Structure of file names

For local resource file names must match the name of the page file, excluding extension.

For example, for index.php resource file by default index.json; for page users.php - users.json etc.

For global resource file is used global.json.

If the resource file for a particular culture (language), the file name must contain the code of this culture. For example, esource file for the Russian language of the index.php should be named index.ru.json, for English - index.en.json etc. Similarly for global resources: global.ru.json, global.en.json etc.

The list of two-letter language code (ISO 639-1) can be found at the following link: http://www.loc.gov/standards/iso639-2/php/code_list.php

Structure of localization files

Resource files are plain text files in the JSON format.

To eliminate errors is recommended to use the UTF-8 without BOM.

Resource files contain arrays of resource elements.

Each element of the resource is written to the object of the following structure: { "Key": "Resource name", "Value": "Resource value" }

Below is an example of the resource file.

[
  { "Key": "PageTitle", "Value":  "Title" },
  { "Key": "Introduction", "Value":  "Introduction" },
  { "Key": "IntroductionText", "Value":  "Built-in localization mechanisms make it easy to adapt the site for different cultures." }
]

The file structure must conform to generally accepted standards of the JSON.

Using the resources localization

To use the resources sufficient to indicate in the text of key resource format: ${RourceKey}.

For examle, for rosource key ThePageTitle, on the page you must place the marker: ${ThePageTitle}, for TheIntroduction - ${TheIntroduction} etc.