Jump to content

multiple languages


jcombs_31

Recommended Posts

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 :/
Link to comment
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.
Link to comment
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. 
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

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.