jcombs_31 Posted August 4, 2006 Share Posted August 4, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/ Share on other sites More sharing options...
ober Posted August 4, 2006 Share Posted August 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-69251 Share on other sites More sharing options...
Koobi Posted August 4, 2006 Share Posted August 4, 2006 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 :/ Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-69363 Share on other sites More sharing options...
ober Posted August 4, 2006 Share Posted August 4, 2006 That's actually a very good explanation, Bane ;) Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-69387 Share on other sites More sharing options...
jcombs_31 Posted August 9, 2006 Author Share Posted August 9, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-72037 Share on other sites More sharing options...
Koobi Posted August 9, 2006 Share Posted August 9, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-72109 Share on other sites More sharing options...
Daniel0 Posted August 11, 2006 Share Posted August 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-72920 Share on other sites More sharing options...
jcombs_31 Posted August 16, 2006 Author Share Posted August 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-75771 Share on other sites More sharing options...
Daniel0 Posted August 16, 2006 Share Posted August 16, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-75773 Share on other sites More sharing options...
effigy Posted August 16, 2006 Share Posted August 16, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16556-multiple-languages/#findComment-75776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.