Jump to content

Recommended Posts

Hi all,

 

I'm starting to work on a fairly big project, and was wondering if any of you have had any previous experience with incorporating different languages on a site... and how you implemented it?

 

I was thinking of doing it this way:

The site will be developed in English, and every bit of static text on the site will go into an English language file, like:

 

<?php

$lang_1 = "Hello";
$lang_2 = "Welcome to the site";
$lang_3 = "This is some further site info";

// ... etc etc

?>

 

Throughout the site, static text is replaced by the variables listed above.

 

After a user signs up, they specify what language they'd like to use. If they select English, the site references the English Language file, and each of the variables on all of the pages are in English.

 

Say if French was available, and they selected it, their $_SESSION language would be set to French, and the site references a Language file that is exactly the same as the English Language file, but every bit of text is its equivalent in French.

 

This way, every user can have localised languages version of the site.

 

The thing I'm worried about though, is that the language files might be very large (like, up on thousands of textual variables to be set) - do you reckon this will affect the page loading times, if the page referenced say 5000 language variables before it got to the HTML?

 

All of your opinoins / experiences are much appreciated.

 

Cheers,

WoolyG

I'd probably store it in an array:

 

//lang_en.php
//Lang variables
$_LANG['en']['story'] = "At 8 o'clock, I went to sleep.";
$_LANG['en']['header'] = "Something";

 

//lang_gr.php
//Lang variables
$_LANG['gr']['story'] = "Στις 8 η ώρα, απόκοιμηθηκα.";
$_LANG['gr']['header'] = "Κάτι";

 

Etc. etc.

 

Then:

include("lang/lang_{$_SESSION['lang']}.php");

 

You get the idea.  Or you could use a database... =P

I use gettext.

 

Ah yeah.  gettext() is very useful.  It even has its own shortcut. :D  _()   What a weird name for a shortcut.

 

Not really. When you create the mo files you'll have to search through the source files to find where the strings to be translated are. So you look for anything within a function/method called _(). I use Zend's gettext implementation though, not the one built into PHP.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.