Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internationalization in PHP

I am currently researching the best methods to integrate i18n into projects.

There's several methods I have thought of doing this, first being a database scheme to store the strings and relevant locale, but the problem with this is that it would not be that easy to select the strings, because i would not like to perform quesries like so:

SELECT text FROM locales WHERE locale = 'en_GB' AND text_id = 245543

Or

SELECT text FROM locales WHERE locale = 'en_GB' AND text_primary = 'hello'

The next method would be to store them within files such as locales/en_gb/login/strings.php and then try and access them via an class specifically developed like so:

$Language = Registry::Construct('Language',array('en_GB'));
echo $Language->login->strings->hello;

The issue with this is I would have to build a system that would update these files via an administration panel witch is very time consuming, not just building the system to manage the strings but actually managing the strings as the site grows

  • What other methods are there that will be beneficial for a large system
  • Is there any automated way to do 'Translation' as such
  • Should I stick with a database method and build a system for users to translate strings with rating / suggest better version ?
  • What systems have you tried in the past and should I look into them or totally avoid them.
like image 341
RobertPitt Avatar asked Sep 21 '10 13:09

RobertPitt


People also ask

What is internalization in programming?

Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by translating text and adding locale-specific components.

What is internationalization in web development?

Internationalization is defined as the process of making sure that your website's platforms, workflows, and architecture accommodated multiple cultural conventions and languages so that you can create localized sites.

What is internationalization in translation?

In the Translation and Localization framework, Internationalization (or 'i18n' as acronymized by researchers) implies the design and development of a content product or application in order to enable a streamlined localization and adaptation process for target audiences from linguistic, cultural and regional ...

What is localization PHP?

Localization in software engineering is the process of adapting the content of a system to a particular locale so the target audience in that locale can understand it. It is not just about changing content from one language to another.


2 Answers

In addition to gettext already mentioned, PHP 5.3 has native Internationalization support

If that's not an option, consider using Zend Framework's Zend_Translate, Zend_Locale and related components for that. Zend_Translate supports a number of adapters, including but not limited to simple arrays, gettext, XmlTm and others.

like image 169
Gordon Avatar answered Oct 07 '22 11:10

Gordon


I've implemented a XML translation utility as part of a bigger project. You can find it here, and a sample translation file is here (en_US).

like image 44
halfdan Avatar answered Oct 07 '22 11:10

halfdan