Internationalization and localization allow PHP applications to support multiple human languages. Internationalization makes an application structured to support multiple locales, while localization adds specific language translations. Common PHP internationalization approaches include message catalogs, storing translations in databases or JSON files. New services like LingoHub automate the process and improve collaboration between developers and translators.
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
Php packages
1.
2. • Introduction ……………………………………………………………………………. 3
• PHP comparison ……………………………………………………………………... 5
• What are locales ……………………………………………………………………… 5
• Message Catalog …………………………………………………………………….. 6
• PHP today Vs. yesterday ……………………………………………………………. 8
o Storing the strings in a relational database ………………….............……… 10
o Message Catalog ……………………………………………………………….. 12
o Storing the strings in JSON ........................................................................ 14
o Lingo Hub …………………………………………………………………...…… 16
• References …………………………………………………………………………..... 20
3. • While everyone who programs in PHP has to learn some English
eventually to get a handle on its function names and language
constructs, PHP can create applications in just about any human
language. Some applications need to be used by speakers of many
different languages. PHP's internationalization and localization
support makes it easier to make an application written for French
speakers useful for German speakers.
4. • Internationalization (often abbreviated I18N--there are 18 letters
between the first "i" and the last "n") is the process of taking an
application designed for just one locale and restructuring it so that it
can be used in many different locales. Localization (often abbreviated
L10N--there are 10 letters between the first "l" and the "n") is the
process of adding support for a new locale to an internationalized
application.
5. According to W3Tech statistics, PHP is used by 80.5% of all
websites and this share is continuously rising. We can safely say
that the web “speaks” PHP. But what about the content? Since PHP
has been around for such a long time (18 years), its history also
tells the story of the evolution of website internationalization. The
first article in our series about internationalization programming
focuses on PHP internationalization and its different dimensions
and options PHP makes possible.
6.
7. A locale is a group of settings that describe text formatting and language
customs in a particular area of the world. A locale name generally has three
components. The first, an abbreviation that indicates a language, is mandatory.
For example, "en" stands for English and "pt" for Portuguese. An optional country
specifier comes next, after an underscore, to distinguish between different
versions of the same language spoken in different countries. For example,
"en_US" and "en_GB" specify U.S. and British English respectively, while
"pt_BR" and "pt_PT" identify Brazilian and Portugese Portuguese. Finally, after a
period, comes an optional character-set specifier. Taiwanese Chinese using the
Big5 character set is encoded as "zh_TW.Big5". Note that while most locale
names follow these conventions, some don't.
8. Back in the days of static websites, the developer would
copy the whole site structure as many times as the
number of locales that the site supported. The
translators would then go deep into the structure to
make the changes directly in the pages. This was tedious
and error prone. The translator would either need to
know the basics of HTML and what should/should not
be translated within the HTML file, or the developer
would have to pull all the text strings, send them to the
translator and then re-insert them back in the proper
place. It was not a very friendly or quick process for
either developer or translator.
9. Then came PHP and the dynamic web. In a dynamic website the
content is stored in a database or a file system, and is being inserted
into templates on each user request. The separation of content,
structure and design became a new mantra of web development.
When internationalizing the website, two steps need to be taken:
1. the developer provides a mechanism and method for content to
be accessible for the eventual translation of the program and its
interface (internationalization)
2. the translator adapts the content to specific language and culture
doing the actual localization.
There are various internationalization mechanisms at a developer’s
disposal and they differ greatly in their complexity, implementation
time, flexibility, efficiency and ease of use for the translator.
10. Another approach to PHP internationalization is to store the static strings
in a database. The most simple implementation is to add as many versions
of every string or text column as there are supported languages. The
specific translations can be retrieved with a single query, so there is no loss
of performance. When support for an extra locale needs to be added, the
code that pulls the translated string does not have to change much if the
naming of the columns is consistent, but every single table containing the
translatable content does (new columns need to be added).
11.
12. To incorporate I18N support into your program, maintain a message catalog of
words and phrases and retrieve the appropriate string from the message catalog
before printing it. Here's a simple message catalog with foods in American and
British English and a function to retrieve words from the catalog:
13. This short program uses the message catalog to print out a list of foods:
To have the program output in American English instead of British English,
just set $LANG to en_US
Note that
14. When using this mechanism, a language file is loaded based on the configured
language. A static array $translations is used to ensure that the language file is
loaded once and every other subsequent call is handled through the $translations
array in the memory rather than reloading the language file anew. The language file is
constructed in JSON format and when the language file is loaded into the
$translations array the PHP json_decode function is used to convert from JSON into
PHP associative array format. When a call is made to the function, a language phrase
is passed to the function and the matching value is found in the $translations array
by using the language phrase as a key for the associative array. The .txt files need to
be utf-8 encoded (without BOM), otherwise the JSON PHP functions will not operate
correctly.
15.
16. All of the listed mechanisms and methods for PHP internationalization
have some common shortcomings, and LingoHub deals with all of
them successfully. If resource files are used as the main i18n method,
and if resource files are uploaded as a part of the LingoHub project, it is
possible:
17. • for developers to automate synchronization
• for translators to focus on translating, without keeping their mind on
the technical methods used for internationalization
• for translators to see the context of the translations (such as meta
information, comments, screenshots)
• for developers to add rules and guidances on how particular
translations should be conducted (e.g. by defining LingoChecks,
setting specific regional variety of a language, setting formal/informal)
18. • for translators, reviewers and developers to communicate and
resolve any doubts on any of the translations using the LingoHub
platform, reducing Email traffic
• for project owners to keep track of the translation status of each
individual translation and the project in general
• for translators to easily and quickly find new or untranslated
phrases using filters, advanced search or notifications
• for multiple people (translators or reviewers) to work on the same
project simultaneously without any worry that they will undo each
others changes (e.g. via roles and permissions)
19. As a result, the PHP internationalization process is less of a hassle,
automated to a much greater degree, better quality control is available
and it is many, many times faster than it used to be. Ask us if you have
questions on how you can best internationalize your project, and check
out LingoHub to localize your product. Zero overhead, comfortable
integrations and scalability as you’d expect it from a cloud service.
20. • PHP Cookbook (By David Sklar, Adam Trachtenberg)
• Stack Over Flow
• GitHub
• LingoHub
• W3Techs
• A simple approach to Localization in PHP – Mind IT | Mind IT