Jump to content

Recommended Posts

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!

 

 

Link to comment
https://forums.phpfreaks.com/topic/150923-solved-multiple-languages-on-a-site/
Share on other sites

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?

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');

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.

 

 

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.