woolyg Posted October 7, 2008 Share Posted October 7, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/ Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658619 Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 Wow, Greek looks like crap in monospaced font. Looks much better normally: Στις 8 η ώρα, απόκοιμηθηκα. Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658636 Share on other sites More sharing options...
woolyg Posted October 7, 2008 Author Share Posted October 7, 2008 Cool, thanks for your input. There could be literally thousands of variables in a language file - do you reckon this will hurt page load times if it's called at the start of each page load? Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658641 Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 Maybe you could separate it out into different lang files for different parts of the site? Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658646 Share on other sites More sharing options...
woolyg Posted October 7, 2008 Author Share Posted October 7, 2008 Ooh - valid point, never thought of that! Nice one DarkWater, that'll help out down the line! Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658648 Share on other sites More sharing options...
Daniel0 Posted October 7, 2008 Share Posted October 7, 2008 I use gettext. Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658768 Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 I use gettext. Ah yeah. gettext() is very useful. It even has its own shortcut. _() What a weird name for a shortcut. Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658869 Share on other sites More sharing options...
Daniel0 Posted October 7, 2008 Share Posted October 7, 2008 I use gettext. Ah yeah. gettext() is very useful. It even has its own shortcut. _() 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. Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658877 Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 How does Zend implement gettext()? I've never even seen Zend's before. Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658883 Share on other sites More sharing options...
Daniel0 Posted October 7, 2008 Share Posted October 7, 2008 http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Translate/Adapter/Gettext.php Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658889 Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 Interesting. Quote Link to comment https://forums.phpfreaks.com/topic/127321-language-modules-on-php-sites-your-thoughts/#findComment-658895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.