Jump to content


Photo

multiple languages


  • Please log in to reply
9 replies to this topic

#1 jcombs_31

jcombs_31
  • Staff Alumni
  • Advanced Member
  • 2,066 posts
  • LocationFL

Posted 04 August 2006 - 03:44 PM

How do people usually make sites in multiple languages? Do they actually create two different files for each page, or store all content into a database and display according to the language selection?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 04 August 2006 - 03:52 PM

In most cases I've heard of, everything is kept in a database and all your content/menu/whatever grabs are done with WHERE clauses like " WHERE lang = 'en' " or something like that.

Info: PHP Manual


#3 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 04 August 2006 - 06:38 PM

yeah a database can be used but you can also use a text file and save your 'language packs'.

i generally have a folder named 'lang', for example.

when the user logs in, i would determine his language of choice (there are a number of ways to do this, either by user input or by browser locale detection)

i would then include the appropriate text file.

i usually use ini files for storing languages. i find that it's not too hard to parse and users find it easy to edit as ell.
you can parse an ini file with parse_ini_file()




here's a sample of an english language ini language pack:
en.php
[greetings]
formal = "Hello, %s"
casual = "Hi %s!"

[bye]
formal = "Goodbye, %s"
casual = "Later %s!"


and of course we must have a Wookie language pack, in case Chewbacca decides to visit the site from his ship :)
wookie.php
[greetings]
formal = "Oombachampawhatamisaying, %s"
casual = "Yooaremyfriendyoucrazywookie %s!"

[bye]
formal = "Dontcalluswellcallyou, %s"
casual = "Getoutofmyface %s!"


now my login screen, for example, would look like this:
$pathToLangFile = 'wookie.php'; //'wookie pack chosen
$username = 'Chewbacca';

$lang = parse_ini_file($pathToLangFile, true)
printf ($lang['greetings']['formal'], $username);




NOTE: here's a little trick...even though you would type your language data in INI format, give it a PHP extension. That way, it would spit out an error if someone tried to access it via the browser (since apache would attempt to parse it as PHP but would error since it's not valid syntax) but the parse_ini_file() function wouldnt have a problem parsing it since it uses a different method to access the file (i.e. not via the HTTP protocol)

this way you keep your language pack free from prying eyes while maintaning full access to it in the way you intended to.






sorry if this seems confusing, i'm not too good at explaining things :/

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 04 August 2006 - 07:24 PM

That's actually a very good explanation, Bane ;)  Thanks.

Info: PHP Manual


#5 jcombs_31

jcombs_31
  • Staff Alumni
  • Advanced Member
  • 2,066 posts
  • LocationFL

Posted 09 August 2006 - 09:07 PM

that is way too much work, you'd have to create an entire dictionary.  It would work for something small, but not full content.

#6 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 09 August 2006 - 11:18 PM

That's actually a very good explanation, Bane ;)  Thanks.

thanks, Chewbacca bring's the best out in me :D






that is way too much work, you'd have to create an entire dictionary.  It would work for something small, but not full content.


well hey creating a content management system is way too much work but somebody's gotta do it if they want it :)


you don't have to create a whole dictionary. just create language variables as and when you need them.

#7 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 11 August 2006 - 08:18 AM

I usually do something similar to Koobi. I just have a file with an array like this:

en.php
<?php
$lang['welcome'] = "Welcome, %s!";
$lang['something'] = "Something";
?>

And then I include it.

#8 jcombs_31

jcombs_31
  • Staff Alumni
  • Advanced Member
  • 2,066 posts
  • LocationFL

Posted 16 August 2006 - 04:49 PM

That still doesn't make sense to me.  It would work great on a small scale, like a calendar where you know the names of the months and days will be there.  But for a complete language transition for all content I don't see how you could possibly do it that way. 

#9 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 August 2006 - 04:56 PM

That still doesn't make sense to me.  It would work great on a small scale, like a calendar where you know the names of the months and days will be there.  But for a complete language transition for all content I don't see how you could possibly do it that way. 


Lots of people (including me) do it. It's not very hard work, as long as you did it from the start. Just add strings as you need them.

#10 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 16 August 2006 - 04:59 PM

I would take the path ober mentioned. Use a database which has values for each language. I would use a translator to fill the database since dictionary systems cannot understand language, but only attempt to interpret it based on sets of rules.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users