Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Localizing Site

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
I have a site that is mostly bi-lingual already with separate MySQL entry "pages" for the two languages. Both languages currently show at the same time and it is no problem making only one or the other show depending upon the visitor's choice.

However, I don't want two separate copies of the various forms but I still want the text on them to be in one or the other language. Short of creating a table with a word or two in each field in two different languages to pull out individually, is there another way in PHP? I am thinking of having all the text for a given form in one field in English and in another field in the other language, then having some kind of substitution on the page. It would then be a simple matter of choosing one field or the other in order to get the selected language but I am not sure where to begin.

For example, there could be a field containing carriage-separated lines, such as:

EnglishText

lang:1:Name
lang:2:Address
lang:3:City
lang:4:Country

There would be a separate field in the same record with the other language.

The HTML part of the form would have

{lang:1]
{lang:2}
{lang:3}
{lang:4}

in place of each title that would be replaced on-the-fly with the appropriate language. Is this making any sense or I am I making it more difficult than it needs to be? Any help to get started will be appreciated.
 
Thanks! I am looking into it now but so far it appears to require a single-processor server environment while I am using a shared server:

The GNU gettext library works on a per-process, not per-thread basis. This means that in a multi-user setting such as the Apache web server it will only work with a prefork MPM (i.e. one process per user). Worker and other threaded MPMs will not work.

It also appears to require something to be installed which I cannot do on a hosted environment:

To use these functions you must download and install the GNU gettext package.

That said, it seems to be what I need IF it can be made to work and IF the text can be placed into a field in the database.

Thanks for pointing it out to me but I'm not sure if I can use it.
 
The gettext() function seems to be working on my development system (not sure yet if it will work on the live shared server) but it's not clear to me if it's getting the translations from my .mo file or if it's getting them elsewhere. I need it to get them from my local file and it does not appear to be doing so because some translations are missing on the page that are in the .mo file. Many characters are also unreadable gibberish so it is not encoding properly. The site was created using latin1, not utf-8.

Code:
$Language = "es_ES.UTF-8";
bindtextdomain('messages', $_SERVER ['DOCUMENT_ROOT'].'/locale/');
textdomain('messages');

if (isset($_SESSION['Locale'])) {
    switch ($_SESSION['Locale']) {
        case '2':
	setlocale(LC_ALL, $Language);
        break;
        case '1':
        default:
	setlocale(LC_ALL, "en_US.UTF-8");
        break;
    }
}

The bindtextdomain() function and it's documentation isn't too clear as it seems to still want to look in the server's locale folder to which I have no access on the live server. It also wasn't clear whether I needed to specify the messages folder or not.

Code:
// This?
bindtextdomain('messages', $_SERVER ['DOCUMENT_ROOT'].'/locale/');

// Or this?
bindtextdomain('messages', $_SERVER ['DOCUMENT_ROOT'].'/locale/messages/');

It is also not clear how to change things like date-time strings when using a custom folder.

Also, the development system has no locale folder called es_ES.UTF-8 (it is es_ES.utf8) but when I change the line abode, no translations appear! My development system is running Ubuntu 9.04 in case that helps.

Any help would be greatly appreciated as I see no other postings here about gettext().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top