PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 19, 2019 2:30 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: OOP design question
PostPosted: Thu Jun 21, 2012 6:27 pm 
Offline
Forum Contributor
User avatar

Joined: Fri Oct 06, 2006 8:12 pm
Posts: 294
I am working on revamping and recoding a web-based (PHP/MySQL driven) game. In the game, we output text as a variable string.

As an example, you might want to output to the user the phrase "Click here to return to the main menu", so we have a language variable file which has:

Syntax: [ Download ] [ Hide ]
$l_return_main = "Click here to return to the main menu";


Then when we need to output it, we do:

Syntax: [ Download ] [ Hide ]
echo $l_return_main;


This "worked" for a while. But we've gotten up to around 1400 variables now, and its starting to have some overhead. A page with just 20 strings of text suddenly has 1400 variables(!)

We're pondering storing it in a database, but during that process, it occurs to me that maybe languages need to be an object. A language object, and then english would extend that. I think the language object would only have a getter and a setter (?)

Am I on the right track here, in terms of design, or am I just seeing an object because I'm tired of staring at 30k lines of procedural-only code?

Any discussion would be *deeply* appreciated.


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Thu Jun 21, 2012 6:32 pm 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887
Well I think any way you look at it the complexity increases exponentially.

That being the case it would be good to store strings in the database with corresponding tokens.

The content should have tokens and be *compiled* if you will into various language templates. In other words, cache a token free version for each language.

This would reduce overhead to virtually nothing.

Off the top of my head I suppose you could have tables for languages, tokens, and token values. Token values would store the token_id, language_id and token_value.

_________________
Image


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Thu Jun 21, 2012 10:17 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 2:00 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
http://www.propelorm.org/behaviors/i18n.html

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 10:09 am 
Offline
Forum Contributor
User avatar

Joined: Fri Oct 06, 2006 8:12 pm
Posts: 294


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 10:34 am 
Offline
Forum Contributor
User avatar

Joined: Fri Oct 06, 2006 8:12 pm
Posts: 294


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 11:52 am 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887

_________________
Image


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 12:03 pm 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887
Honestly I like my idea to compile versions of each file into each language.

For example this:

Syntax: [ Download ] [ Hide ]
<?php
echo "Hello {#WORLD}";
?>
<h1>{#MAIN_HEADING_HELLO_PAGE}</h1>
 


Would become this for the english version:

Syntax: [ Download ] [ Hide ]
<?php
echo "Hello World";
?>
<h1>This is an example</h1>
 


Then your template loader can just load the corresponding file and all the code remains intact. If you modify any code just recompile all the language files.

_________________
Image


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 3:53 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: OOP design question
PostPosted: Fri Jun 22, 2012 4:11 pm 
Offline
Forum Contributor
User avatar

Joined: Fri Oct 06, 2006 8:12 pm
Posts: 294
Great replies everyone, exactly what I was looking for. Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group