Jump to content

Archived

This topic is now archived and is closed to further replies.

jcombs_31

multiple languages

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
[code=php:0]
[greetings]
formal = "Hello, %s"
casual = "Hi %s!"

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


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

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


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

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




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 :/

Share this post


Link to post
Share on other sites
That's actually a very good explanation, Bane ;)  Thanks.

Share this post


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

Share this post


Link to post
Share on other sites
[quote author=ober link=topic=102991.msg409757#msg409757 date=1154719476]
That's actually a very good explanation, Bane ;)  Thanks.
[/quote]
thanks, Chewbacca bring's the best out in me :D






[quote author=jcombs_31 link=topic=102991.msg412712#msg412712 date=1155157644]
that is way too much work, you'd have to create an entire dictionary.  It would work for something small, but not full content.
[/quote]

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.

Share this post


Link to post
Share on other sites
I usually do something similar to Koobi. I just have a file with an array like this:

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

And then I include it.

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites
[quote author=jcombs_31 link=topic=102991.msg416916#msg416916 date=1155746996]
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. 
[/quote]

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.

Share this post


Link to post
Share on other sites
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 [i]understand[/i] language, but only attempt to interpret it based on sets of rules.

Share this post


Link to post
Share on other sites

×

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.