br0ken Posted March 24, 2009 Share Posted March 24, 2009 I'm attempting to seperate all of the text displayed to users into a seperate file. Examples of the text I'm moving are error messages, page titles and every thing else. With all text in one place it will make it much easier for someone who isn't technical to edit. It will also allow me to make different language versions of my site. Can any one recommend any good ways of doing this? My first idea was to declare each one as a constant but I'm not sure what effect having hundreds of constants would have. Another idea was to put the whole in a switch statement inside a function and pass a parameter to the function. This seems like an extremely bad idea though. Does any one have any suggestions or advice? I know this can be done because I saw a company do it about 6 years ago when I first started getting into programming. Unfortunately, I can't remember how they did it! Quote Link to comment https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/ Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 Why not include everything into a language file at the start of each page like you would dbconnect? $lang['en']['title']='Site Title'; $lang['en']['yes']='Yes'; $lang['en']['no']='No'; $lang['en']['submit']='Submit Data'; Quote Link to comment https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/#findComment-792896 Share on other sites More sharing options...
br0ken Posted March 24, 2009 Author Share Posted March 24, 2009 That is exactly what I'm planning on doing. I'm not sure of the correct method to do this. Like I said I could store each value as a constant, in a function or in an array like you've suggested. I was wondering if any method would be better than another. I think it's between constants and arrays. I'm going to be having a couple of hundred different values so would that affect the speed or woudl it not matter? Quote Link to comment https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/#findComment-792906 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 I've used the way I've posted and not had a performance hit or anything. Whatever method you feel easiest with I suppose. If you remove the ['en'] part you can have separate files (ie. named language_en.php, language_no.php, language_fr.php etc.) and include them in like: include('language_'.$lang,'.php'); Quote Link to comment https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/#findComment-792915 Share on other sites More sharing options...
br0ken Posted March 24, 2009 Author Share Posted March 24, 2009 I think I'll give that a go then. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/#findComment-792917 Share on other sites More sharing options...
laffin Posted March 24, 2009 Share Posted March 24, 2009 Use a database and a cache The database will house yer strings. while the cache, houses the preprocessed pages (lowering the load time for the pages) the db for the strings can be simple. One table for the language names and one for the strings themselves create table languages ( id INTEGER PRIMARY KEY, language VARCHAR(32) ); create table strings ( id INTEGER PRIMARY KEY, lid INTEGER, sid INTEGER, string VARCHAR(255) ); The languages table is optional, but it is nice to have to add/remove languages and provide a drop down box for the strings, u will use lid = language id and sid = string id now ya can build a string editor, In a few sites, I always used english as 1, this way when I built the editor. I can use the english strings as the default for the editor. Quote Link to comment https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/#findComment-792922 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.