1

I have a website that I want to produce into a multi lingual website.

But, I am stuck. Should I use XML or PHP array? I was going to do it with XML, but when I saw this website: php array

It looks much easier doing it this way than xml. So, I want to know if there's any pro and con between these two styles?

Ya Fa Su
  • 160
  • 1
  • 4
  • 13
  • There is a similar topic http://stackoverflow.com/questions/2319060/using-php-gettext-extension-vs-php-arrays-in-multilingual-websites – JScoobyCed Feb 22 '13 at 04:06

2 Answers2

2

You should not use XML for language. It will broke up code when you are using some characters which isn't supported into UTF-8 standards.

It's much easer using POEDIT application for quick editing language in GUI on linux and parsing a file .MO and .PO

Please avoid XML for language parsing. This will slow down your performance.

Look this how to use POEDIT: http://www.dev4press.com/2010/tutorials/wordpress/various/translating-plugins-or-themes-using-poedit/

This will generate a language therms.

Then you need to use gettext to parse and read localization. Look this page for example explanation: http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/

And really after poedit and parsing a gettext data explanation is here: Create POT file with Poedit

Skip to this site for real practices: http://www.codeforest.net/translate-and-localize-your-web-application-with-php-and-gettext

GETTEXT SPEED improvements vs. variables: http://mel.melaxis.com/devblog/2006/04/10/benchmarking-php-localization-is-gettext-fast-enough/

Community
  • 1
  • 1
Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53
  • I like the idea to advise for .po/.mo, but I think it would be nice to explain the pro/cons compared with the plain array solution (from OP link) as it looks really easy and doesn't require other tool to generate the PO/MO. – JScoobyCed Feb 22 '13 at 02:46
  • Oh thank for that didn't know that thing will take a look, but I already have all texts and information in a Excel file, just have to convert them into a xml file or php array file. – Ya Fa Su Feb 22 '13 at 02:47
  • Convert it from excell to usable in POEDIT. Gettext use binary parsing and is faster than reading classic variables. XML need to parsing and reading, but gettext is heap into memory and is on. This is GETTEXT comparision speed tests: http://mel.melaxis.com/devblog/2006/04/10/benchmarking-php-localization-is-gettext-fast-enough/ – Marin Sagovac Feb 22 '13 at 02:51
  • hehe, now I understand how it works XD, thank you. – Ya Fa Su Feb 22 '13 at 03:05
  • "It will broke up code when you are using some characters which isn't supported into UTF-8 standards" -- what is this supposed to mean? – Michael Day Feb 22 '13 at 03:34
  • I have experienced with UTF-8 XML and didn't want parsing all characters like chinese strings, and other characters which isn't on UTF-8 range: http://scn.sap.com/thread/191843 – Marin Sagovac Feb 22 '13 at 03:36
1

In my opinion, it depends on how big your website is and how much translation is involved.

Parsing XML would take some more time than just including a php file with the defines but, that won't be a deal breaker.

I'd find it easier in terms of maintenance to use XML, that would allow you to even create nodes based on page names or other attributes to sort their content

<page name="homepage">
   <tag name="tittle">Titulo</tag>
   ..
   ..
</page>
<page name="products">
   <tag name="product-title">Producto</tag>
   ..
   ..
</page> 

You may also want to take a look at PHP's internationalization guide in case you need a bit more than just multiple language support http://php.net/manual/en/book.intl.php

Marcelo C.
  • 118
  • 2
  • 10
  • Author wrote 'but I already have all texts and information in a Excel file' so I'm thinking that these data can be huge. In this way if it will slow performances this should be not to use XML parsing. – Marin Sagovac Feb 22 '13 at 02:56
  • yea thanks, its about 9 to 10 pages. So, I think I will give a try on the php one, thx. – Ya Fa Su Feb 22 '13 at 03:02