Posted 04 August 2006 - 03:44 PM
Posted 04 August 2006 - 06:38 PM
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:
[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
[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 :/
Posted 09 August 2006 - 09:07 PM
Posted 09 August 2006 - 11:18 PM
thanks, Chewbacca bring's the best out in me
That's actually a very good explanation, Bane Thanks.
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.
Posted 11 August 2006 - 08:18 AM
<?php $lang['welcome'] = "Welcome, %s!"; $lang['something'] = "Something"; ?>
And then I include it.
Posted 16 August 2006 - 04:49 PM
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.
Posted 16 August 2006 - 04:59 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users