PHP Localization Best Practices? gettext?

We are in the process of making our website international, allowing multiple languages.

I've looked into php's "gettext" however, if I understand it right, I see a big flaw:

If my webpage has let's say "Hello World" as a static text. I can put the string as <?php echo gettext("Hello World"); ?>, generate the po/mo files using a tool. Then I would give the file to a translator to work on.

A few days later we want to change the text in English to say "Hello Small World"? Do I change the value in gettext? Do I create an english PO file and change it there? If you change the gettext it will consider it as a new string and you'll instantly loose the current translation ...

It seems to me that gradually, the content of the php file will have old text everywhere. Or people translating might have to be told "when you see Hello World, instead, translate Hello Small World".

I don't know I'm getting confused.

In other programming languages, I've seen that they use keywords such as web.home.featured.HelloWorld.

What is the best way to handle translations in PHP?



You basically asked and answered your own question, the answer might just be having a slightly better understanding of how PO files work.

Within the PO file you have a msgid and a msgstr. The msgid is the value which is replaced with the msgstr within the PHP file depending on the localization.

Now you can make those msgid's anything you would like, you could very well make it:

<?php echo _("web.home.featured.HelloWorld"); ?>

And then you would never touch this string again within the source, you only edit the string through the PO files.

So basically the answer to your question is you make the gettext values identifiers for what the string should say, however the translators typically use the default language files text as the basis for conversion, not the identifier itself.

I hope this is clear.

Currently, I am dealing with the same issue. The common practice with gettext is to use the English text as the key. Recently, our copy editor changed whole bunch of English text (other languages are hardly touched) so we have to change all the source code all the PO files.

We are switching to a neutral key. Since we already have some sites on Java. We will use the same property name format.

I know an answer has been accepted, and the above answer is good. But there is another issue with using permanent machine-style keys like thing.stuff.widget when working with Gettext.

While using permanent keys is a better approach to development, Gettext is not set up for that style of working and this can complicate your workflow.

If you present a translator with a PO file populated with keys in place of source text, they may not know what the English should be. So you'd have to provide them with a second file containing source language translations for them to compare to. Not the end of the world, but more fiddly for them and not how Gettext was designed. (square peg, round hole etc..)

I think PO is perfectly fine as a file format for translations in PHP, and especially recommended if you're not working with a framework that has a good l10n module, but that doesn't mean it's good for workflow and your translation process.

I suggest you arrive at a workflow that allows your programmers to work with permanent keys, your translators work with words, and gives you a MO file out the other end. Take a look at Loco for one solution to this.

Alternatively use a different interim file format that allows the use of keys and words. TMX is one example. If you still want to use Gettext at runtime you can convert the files.

Category:php Time:2010-05-07 Views:3

Related post

  • C++ Localization best practices? 2009-03-06

    We are localizing a cross-platform C++-based client-side application. The first localization pass was done in a big rush for a big partner on a short deadline, and now it's time to refactor it. We currently have an XML strings file per locale, with a

  • Content localization best practice 2009-11-18

    If we are going to localize content so we can retrieve SAME content item in different languages what would be the best practice? One solution is to put localized content into separate class (table): public class Category { public Guid ID {get;set;} p

  • Java localization best practices 2010-09-02

    I have a Java application with server and Swing client. Now I need to localize the user interface and possibly also some of the data needs to be locale specific. There are few things in specific I would like to hear your opinions on. How should I dis

  • Ruby localization: i18n, g18n, gettext, padrino- - what's the difference? 2011-06-21

    Being somewhat new to Ruby I'm exploring existing libraries to do what I'd normally do in other scripting languages, and I'm a bit stumped by the localization libraries that might be available for something built on top of Sinatra/Sequel (Rails/AR be

  • Web application date time localization best practice at 201x 2011-01-18

    I have worked for various web projects but correct date time localization have not been done and considered throroughly so I want to ask this very typical problem here and I want to hear comments from expert in this problem What is the correct strate

  • Storyboard/XIB and localization best practice 2012-01-13

    The officially recommended method for XIB/Storyboard localization is to create .xib and .storyboard files inside xx.lproj (where xx is the two letter language ID) for each localization you want to support. This creates a problem because you have mult

  • Localization best practices 2010-01-25

    I'm starting to modify my app, which uses all hardcoded strings for errors, GUI, etc. I'm considering these two approaches, but let me know if there is an even better way: -Put all string in ressource (.rc) files. -define all strings in a file, once

  • Localization of Text File resources in .NET 2010-07-22

    Localization/Globalization is pretty easy in Visual Studio using RESX files. I just add a resource file, like MyTextSnippets.resx, add key/value pairs, and create copies for every language I'd like to support like, MyTextSnippe

  • Localization Logistics and Software 2011-05-30

    We are in the process of expanding the localization of our web based (C#) application from 6 languages to 11. Even with the current language offerings we are struggling with the logistics of localizing - we are suffering from a range of issues: Seemi

  • C#, Localization, Resources, and MonoDevelop 2011-07-04

    I've searched for a clear answer on this, but can't seem to find one. I may just be missing it on StackOverflow, and searching discussions regarding SharpDevelop and MonoDevelop have yielded nothing either. I apologize if this has already been asked,

  • Localization: Sub-Domain, Directory or Domain 2011-07-08

    I'm about to embark of my first multilingual website and I'd like to get the opinion of everyone... The site will be utilizing jQuery, so there's always the option of using a combination of jQuery and the Session to manage locale. What method have yo

  • php-gettext isn't working 2011-12-04

    I'm trying to setup localization using php-gettext, but it doesn't seem to work no matter what. I have an index.php: <?php require_once "localization.php";?> <a href="?locale=en_US">English</a> | <a href="?locale=de_DE">German

  • Use format strings that contain %1, %2 etc. instead of %d, %s etc. - Linux, C++ 2010-12-26

    As a follow-up of this question (Message compiler replacement in Linux gcc), I have the following problem: When using MC.exe on Windows for compiling and generating messages, within the C++ code I call FormatMessage, which retrieves the message and u

  • iPhone support Multiple Languages 2011-01-04

    In my project, I need to support the Korean language. How is it possible - can anyone explain briefly with example, whether it is possible or not? --------------Solutions------------- It's certainly possible. You just tell Xcode to add a Korean local

  • In C, what is meant by "format argument can be an expression too"? 2012-03-06

    In the K&R book, it shows the following printf statement in the pointers chapter: printf((argc > 1) ? "%s " : "%s", *++argv); I don't understand this line - why are there two %s in here? Thanks! --------------Solutions------------- That's equi

  • Translating a db into different languages 2014-03-25

    I'm using gettext for the translation of my webpage. I already have almost of my webpage translated in four languages (Spanish, English, French and Portuguese). I only have translated the things in my php files. What I want is to also translate the t

  • Best practices for ASP.NET web application localization 2009-01-18

    I'm developing a web application that will need to be localized to English and Portuguese (and possible more languages later). I'm aware that the .NET Framework offers full support for UI localization, however, I'm not so sure what's the best approac

  • Pros and cons of using gettext instead of for localization of PyQt4 application? 2010-01-07

    I have couple of application written in PyQt4 where I've used standard Python gettext library for internationalization and localization of GUI. It works good for me. But I've selected gettext just because I've already had knowledge and experience of

  • Java: Best practice for sharing localization object across many GUI objects? 2010-02-28

    What would be the best practice for sharing localization object (in this case ResourceBundle, where I do save all translations) across many GUI objects in app? I have few ideas, but both have drawbacks: 1) passing ResourceBundle via each GUI class co

Copyright (C), All Rights Reserved.

processed in 0.475 (s). 13 q(s)