The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Development
  • Server Side
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Development
 Server Side

  • Pixware Author 
    • 266 
    • 0 
    • 7 
    [PHP] Multi language
    Pixware

    Last reply Feb 03 2007, 10:06 AM

    by Pixware

    Posted: Jan 29 2007, 12:11 PM

    by Pixware

     

I bet this one’s gonna hit you hard! Not.

I’ve been asked by a client to make a site in three languages. Now, I’ve never tackled such a task. And I’m pretty sure some of you actually have. So I beg you (*lol*) to share your wisdom with this humble coder. I’ve been spitting out ideas like using a database table for strings used around the site, and echoing them according to the language, which I may store in a cookie or the session. Then I’ve been thinking of plain text files, using some king of separator and containing those strings in some order. Both of these will require a strict coordination of string identifiers and their positions on the site. And both will give me the ability to easily outsource the translations if I need so (I speak the 3 languages fluently, but I might be short of time…)

Now please tell me your thoughts. I promise I’ll even be around to answer big grin

  7 REPLIES
 
Pixware Author 
1  
Pixware

I’m pretty sure there’s someone here knowing more than me on this topic. Anyone to share his/her knowledge?

  • 30 January 2007 08:19 AM
  •  
poppa
2  
poppa

If you’re running a Linux server you can checkout gettext (I don’t think it works on Windows, but I’m not sure).

I’ve done a more simple solution that’s platform independent and I can give you an example later when I get back from work.

Cheers

  • 30 January 2007 08:53 AM
  •  
Pixware Author 
3  
Pixware

I’d really dig that, poppa. You’re the man wink

  • 30 January 2007 09:47 AM
  •  
petremetre
4  
petremetre

I use to create a .php file where i define all my string variables and use these within my pages instead of text.
If text is stored in a database i create multiple table and access them accordingly by a table prefix i.e. gr_news, eng_news, de_news etc.

Cheers
‘A’

  • 30 January 2007 12:03 PM
  •  
poppa
5  
poppa

Okey, here we go:

The code is popped out of a project I’m working on but I think I got it pretty generic.

You’ll see that there are some <langcode>.lang.php files in there and these are the files with the actual translations. Note, that you can very well populate the array in these files with content from a DB. They are just regular PHP files with a single array and how you populate these arrays is up to you.

At the moment the code decides what language to use based on the primary language set in the user’s browser. But there would be no problem implementing the ability to swap language manually.

Last in the Locale.php you’ll see a function called getLocale which returns the Locale object. The function assume you name your locale object $LOCALE but if you name it something else just change that function accordingly.

You’ll find the code here, and there’s an example implementation. If you use Firefox you can add “Swedish” to languages and set it as default to see the example live.

[EDIT]
Here are two screen dumps, one where I have Swedish as default language and one where I have English:

locale-sv.png
locale-en.png
[/EDIT]

If you have any questions just ask.
And BTW: This is PHP5 code.

  • 30 January 2007 02:47 PM
  •  
Pixware Author 
6  
Pixware

I have been looking into gettext since your last post. Seems like neat stuff. I’m not really for the idea of using arrays of strings and of the kind.
I’ll have a look at your solution before deciding. Thanks poppa!

  • 01 February 2007 02:40 PM
  •  
Pixware Author 
7  
Pixware

I’ve been thinking on this subject for two days now. I’ve decided, I’m going with a mixed solution. On one side, my static content is going to be stored in arrays. It’s a fairly low amount of strings, so it should be fairly maintainable. If the amount ever increases I can always switch over to gettext, which I have been unable to get to work with CakePHP. On the other side, a big part of the site’s content is editable through a hand crafted cms, and the client needs to enter most of this information in several languages. This leads me to store these strings in a translations table in my database. However, I’m still unsure about the exact structure of my data. Consider this a rant.

This site is getting interesting. I’ll be writing a little guide for my upcoming weblog.

  • 03 February 2007 10:06 AM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 779  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,728  Assets
  • Profiles 282,751  Members
  • Topics 93,776  Topics
  • Blog 4  Blog
  • Facebook 1,679  Facebook
  • Twitter 1,163  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 11, 2012 - 19:59:54