Creating a multi-Language website - Static or Dynamic? - php

I am creating a website and it has to be multi-language. The translation has to be made and prefixed (NO auto-translations api). My question is, what is more efficient?:
Create one file set for each language.
Create one file set and show text through PHP constants.
I also thought of making a MySql query to get an array with all translations at the beginning of the document.
Note:* There will not be really large texts.

Longer term, you're best option is going to be using one file set for each language. If you use an industry standard format, such as GNU gettext, PHP has built in support. Also, 3rd party translation companies and translation tools generally support the format, so long term site maintenance requires less dependencies on developers.

I'm using Zend Translate for a website I'm working on.
Most of the components in Zend Framework can be used as standalone components. I'm using the full stack but it shouldn't be a major problem to use only Zend Translate.
As for using a database to get translations, I think it depends on the type of content you are dealing with. For instance, for Joomla! there are components that store different versions of the same article, in different languages.
I would recommend Zend Translate, as you have different options to get the translations from: PHP arrays, INI files, gettext, xml.
You can event extend the adapter class to create a database backend adapter.
Hope it helps.

I think it will help you: http://www.youtube.com/watch?v=v7vCp_TFcdU
It uses session to store the chosen language and use an array for each language.

Related

multilingual Content managed website (CMS) using zend framework

Although I find quite a lot resources related to this question but none of them is precisely giving the answer to a Multilingual CMS using Zend Framework.
There are many zend translate adapters available in zend framwork. But the one (zend sql adapter), which is most need for database(mysql) driven websites, is not yet released.
For those multilingual websites, which are not database driven, contents can be placed in files (xml, mo, or any other) and one of the zend translate adapter is used to process the contents to display the correct language.
How we will deal with database driven multilingual website? Previously we were habit of using php with well-designed multilingual database keeping each article (page) in table with every required translation. If we will do the same by using zend framework, would that be over kill or slow website? We still make use of zend cache to make it faster, but we won't able to take the advantage of zend translate. Later, when the zend translate adapter for sql will be available, would that be easy to switch that multi-lingual content managed system by using zend translate.
Has anyone tried this? What could be the pros and corns?
Another solution could be keeping our well design multilingual database and generate xml based language files on every change admin make using GUI in admin area. And then use one of zend translate adapter to handle these xml files. I guess that could be overkill, killing a bird with cannon :)
When I am talking about placing the whole page's content in database. It can include some html tags such as b, span, br, p etc. How well the zend translate can deal contents with html tags in it?
If someone already has implemented this before, what could be the best way to deal with Multi-lingual content managed website using zend framework.
Any expert opinion!
There are many zend translate adapters available in zend framwork. But the one (zend sql adapter), which is most need for database(mysql) driven websites, is not yet released.
For those multilingual websites, which are not database driven, contents can be placed in files (xml, mo, or any other) and one of the zend translate adapter is used to process the contents to display the correct language.
These are wrong assumptions. It is not said, that DB driven application needs to use DB driven translate system. You can easily use static-files system.
How we will deal with database driven multilingual website? Previously we were habit of using php with well-designed multilingual database keeping each article (page) in table with every required translation.
I think that you are a little bit mistaken - I understand that you would like to use Translate for the dynamic content of your page (articles). Translate is rather designed to internationalize the views - the static content. I mean things like login or register or welcome text, etc. And these really should be in the files (consider files a static cache) rather than in the DB, because of huge load it would make (DB should be cached anyway). The articles stored in the DB is a different thing, and what you want to achieve is multilangual page content. You can handle that easily without Translate (remember, Translate is good for views!), simply add a country/language flag to your tables and retrieve suitable (filtered for given language) data through your model. It is really straightforward and it doesn't need any backend for translation.
I am not sure how Translate works, but I can assume that it checks the language and then loads whole translation file and stores it in script memory as a collection (or simple associative array) just to provide quick and robust translation mechanism (notice, that it wouldn't need to call a DB or a file for every given key, because all of them would be in the memory). Keeping the whole pages, articles this way wouldn't make sense at all, mainly because you need only 1-2 articles per page (why waste memory then?) and sometimes a hundreds of localized view strings (so you don't want to make a call to a DB or file for each of them)
Another solution could be keeping our well design multilingual database and generate xml based language files on every change admin make using GUI in admin area. And then use one of zend translate adapter to handle these xml files. I guess that could be overkill, killing a bird with cannon :)
If talking about translations for a static content - it really is very common solution: keeping the translations in the DB for easy access/change and generating the XML/CSV/whatever files when change occurs.
When I am talking about placing the whole page's content in database. It can include some html tags such as b, span, br, p etc. How well the zend translate can deal contents with html tags in it?
It would probably deal good, but still, you are thinking about dynamic content. Static content should be formatted inside the view. So, dead end I guess.
Bottom line: Using Translate for all of that you mentioned, it would be killing a bird with a cannon :)

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.
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.
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).
The most impressive method to study is Drupal's implementation. Second best, would be Wordpress. Both use gettext and .pot/.po/.mo for localization. And, the good thing is that there is a beautiful Open Source .po editor called Poedit. It's available for Windows System users, which gives a wider appeal. It's also available for Mac and Linux. Check it out here: http://www.poedit.net/
Have a look at the Gettext (http://php.net/manual/en/book.gettext.php) library.
Don't put your text into a database. That'll just make life hard on the translation team.

Better to use multiple language files or 1?

From your experience, is it better to use 1 language file or multiple smaller langauge files for each language in a PHP project using the gettext extension? I am not even sure if it is possible to use multiple files, it is hard for me to test since the server caches the language files.
I am doing multiple languages on a social network site, so far just the signup page which is about 1 out of 200 pages to go and it has 35 text strings to translate, at this pace the language file for each language wold be really large so I was thinking maybe it would be better to do different language files for differnt pages or perhaps sections like forums section and blogs section but if it makes no difference then I would ratther not waste my time in making multiple smaller files for each language.
I realize every situation is different and the only real answer is to test it but I am hoping to avoid that this time and just get some oppinions of people more experienced, this is my first time using gettext, thanks
I would have the language files module based. With gettext you need to specify locale for each language. It would fit best to have a separate .po/.mo files for each module or big parts of your site.
That's my opinion. :-)
I typically automate the process and have multiple languages in multiple files by using a database to edit the site (using a simple db lookup). This lets me hire translators to come in and verify the current translation easily. Deploying to production then is simply turning the database into a set of language files.
From experience i would break the languages down on a per file basis as the management overhead becomes heavy and there is great scope for duplication and mistakes.
The other advantage it that by using a directory structure and naming convention the correct language can be selected programatically more easily than the large file and it is easier to write management tools at a later stage in the project.
It is also worth looking at some of the formats other people use. Many of the Frameworks use this sort of structure, Dashcode, Symfony, Zend etc. And there is an xml format xliff which is built to handle translation and integrates with many of the tools that translators use.
Multiple files are the best way to go, but things can get disorganized.
We've just launched a free new service called String which solves most of the problems of managing multiple language files - like a basecamp for localization. You can either import existing files, or start from scratch with keys and strings in the system. When you're ready, you can export the files again to run your app. It works with PHP (array), PHP (define), po, yaml, ini and .strings formats.
String allows you to collaborate with translators easily - you just invite them to a project and set their language permissions. Translators can leave comments and questions on each string if they need more info - and you can revert strings back using the History function if things aren't quite right.
Anyway enough sales pitch!
Check it out at http://mygengo.com/string - we'd love your feedback.

what is the best method to build "multilingual" script in php?

I am building a website and it need to be in 7 languages?
I was wondering if there is a good practice can be applied to get multilingual php script?
Easy for me
Easy for the translators
Also what do you think , should I Store it in DB , XML or in PHP file?
There are plenty of options for storing translations:
TMX: A relatively new XML format for translations. Seems to be gaining in popularity.
Gettext is another open format for translations. Been the de-facto standard for a long time.
ini files - easy to edit, very simple format
PHP files (arrays) - easy to edit for PHP programmers, good performance
CSV format - relatively simple to use.
I'd suggest you use something like Zend_Translate which supports multiple adapters and provides a basic approach to embedding translations in your application.
Contrary to daddz I would recommend against using gettext in PHP:
The locale setting is per-process. This means that when you are working with a multithreaded apache or any other multithreaded webserver running PHP in-process, calling setlocale in one thread will affect the other threads.
Because you can't know which thread/process is handling which request, you'll run into awful problems with users intermittently getting the wrong locale.
The locale you set in PHP has influence on functions like printf or even strtotime. You will certainly get bit by "strange" number formats arriving in your backend code if you work with gettext/setlocale
Use any of the other solutions lined to by Eran or quickly do something yourself (PHP arrays work very nicely). Also use the intl-extension which will be in core PHP 5.3 for number and date formating and collation.
Using gettext on a web based solution over and over proved to be quite like opening the proverbial can of worms.
I'd suggest Gettext.
It's cross-platform, open-source, widely used and available for php: PHP Gettext
I have built multilingual CMS. All content was stored in a database, with main tables for common (not language specific values) and separate tables for the language specific content.
For instance, let us imagine storing products - we have a 'products' table (contains unique_id, date created, image urls etc etc) and a 'product_local' table (contains any language specific fields).
Using this method it is very easy to maintain content.
I have no experience on gettext so no comment on that topic, but I have built a few multi-lingual sites using the following methods:
METHOD 1
I wouldn't say my format is the best, just that it's effective. I've also used array. Depending on where the content is stored.
For example, I'll have an associative array of text with the indexes identifying which text:
$text['english']['welcome'] = "Welcome to my site. blah blah blah";
$text['english']['login'] = "Please enter your username and password to login";
And maybe set your language with a constant or config variable.
METHOD 2
I've built two sites with identical structures and back-ends but each one used a different database and were maintained separately: data_french, data_english.
You may find this article on the topic an interesting read:
http://cubicspot.blogspot.com/2011/12/cross-platform-multilingual-support-in.html
The author advocates a "lazy programmer" strategy - do it only if you need multilingual stuff - and seems to recommend the PHP array approach with IANA language codes. The article is kind of vague though.
Check this forum. I think you'd probably need a different approach if you have somebody helps you with translation.
Most efficient approach for multilingual PHP website

What are good tools/frameworks for i18n of a php codebase?

I have been looking at a few options for enabling localization and internationalization of a dynamic php application. There appears to be a variety of tools available such as gettext and Yahoo's R3 and I am interested in hearing from both developers and translators about which tools are good to use and what functionality is important in easing the task of implementation and translation.
PHP gettext implementation works very smoothly. And po files with po edit and gettext are about as good a way as you can get to deal with localization bearing in mind that no solution of this kind can completely handle the complexities of the various languages. For example, the gettext method is very good on plural forms, but nothing I've seen can handle things like conjugation.
For more info see my post here: How do you build a multi-language web site?
We've been tinkering withZend_Translate, since we use the Zend Framework anyway. It's very well documented and so far extremly solid.
In the past, I've pretty much used my own home-grown solution mostly. Which involves language files with constants or variables which hold all text parts and are just echo'ed in the view/template later on.
As for gettext, in the past I've heard references about PHP's gettext implementation being faulty, but I can't really back that up nor do I have any references right now.
There are a number of useful extensions in pecl:
http://pecl.php.net/packages.php?catpid=28&catname=Internationalization
In particular, you may want to check out php-intl, which provides most of the key i18n functions from International Components for Unicode (ICU)
the database driven solution to show the messages is not always the good one, I worked in a site with more than 15 languages and translations were an issue.
so our design was:
translation app in php-mysql (translation access, etc.)
then translations are written in php arrrays
these arrays are also cached in APC to speed up the site.
so to localize different languages you only need do an include
like
<?php
include('lang/en.php');
include('lang/en_us.php'); // this file overrides few keys from the last one.
?>
Xataface can be used to quite easily internationalize an arbitrary PHP/MySQL application. It support translation of both your static text, and your database data. All you have to do is add a line or 2 of code to a couple of places in your application and it's good to go.
http://xataface.com/documentation/tutorial/internationalization-with-dataface-0.6

Categories