Jump to content

Recommended Posts

for example, if I had 200 files and I would want em to be displayed in diff languages, would one single file, containing all the text kill my server? Cause I can imagine that this file will be somewhere around 300kb if not more? and if I have an include '/languages/en/index.php'; in every single file, would it always load the 300kb everytime someone goes to that page?

 

I'd just like to know what the best way would be to do this.

 

I just thought I put em all into one file, because text like 'Save', 'Submit' and 'Cancel' will appear more than just once in diff. files. so to have a single file for every site would mean I'd have Cancel 200 times.

 

Anyway, I'd appreciate any comments/thoughts on this. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/89039-language-file-php-load-time/
Share on other sites

Im not 100% sure if I understand your problem here. But assuming I do (you want to display one page format in many different languages) this is what you can do.

 

First, use php to check the users' language on their browser (google this). Then set that language into a $_GET variable.

 

Then you store the different text for a page into tables in a database. For example, if you have page 1, you set up a table in your database for that page. You then create the following columns in your database:

 

Page ID

Language

Text 1

Text 2

etc...

 

So if you want to set up English and Japanese for page1.php, in your database you create the following two rows:

 

Table Name: pagetext

pageID      Language        text1                    text2              text3

page1.php      En          Good morning    Good Afternoon    Goodbye

page1.php      Jp              oyaho              konnichiwa        sayonara

 

Then, in your PHP, you do something like this:

 

<?php
$query = "SELECT text1, text2, text3 FROM pagetext WHERE language='". $_GET['language'] . "' AND pageID='" . [use some function here that echos your current page name] . "' LIMIT 1";
$page_text = mysql_query($query);
$page_text = mysql_fetch_array($query);

echo $page_text['text1'] . "<br />";
echo $page_text['text2'] . "<br />";
echo $page_text['text3'];

 

So if you enter the address www.somesite.com/page1.php?language=En, your output will be:

 

Good morning

Good Afternoon

Goodbye

 

and if you enter www.somesite.com/page1.php?language=Jp, your output will be

 

ohayo

konnichiwa

sayonara

hi, thanks for gettin back to me

 

i just thought ill use a php file instead

 

/languages/en/index.php for example:

 

<?php
$l['text1'] = 'Text 1';
$l['text2'] = 'Text 2';
$l['text3'] = 'Text 3';
?>

 

i dun wanna use mysql for doing that.. its a good idea tho. but i just thought itd be better to use a php file instead cause of loadin time.. and its text that wont change anyway.. its just information for users

 

but my problem is, which might not even be a problem ..i have this file ..and its huge.. i mean, im not quite done yet, but it might have 200kb ..so it will contain ALL the text i have on my entire website just in this ONE file..

 

and on every single page i have

 

include 'languages/en/index.php';

 

for example

 

..and i just wonder, when a user goes on that page (which may only contain a few words from THAT text file), will it load the entire 200kb just for those few words?

 

cause i could imagine ..if there are more users, and the server always has to reload the 200kb just for the TEXT.. that my cpu could explode, lol or i dunno.. or will it only look for the variables contained in that page anyway? i hope this makes sense lol ..i dunno, i just thought i should ask, before im compeletely done with all the text and then it probably wont work anyway.

 

but thanks for helpin me out here;)

i dont see whats there not to understand.

 

i have a website. and i want people to view it in different languages. and i need to change the text according to the users settings. english/german/spanish ..whatever

 

so i created an external file for ALL the text. any text that appears on the SITE that is NOT in the databank (meaning, all the text that hasnt been inserted by a user -> its text I created, and text that will probably never change.)

 

for example

 

Cancel

 

i have that word in my text file under, ie:

 

languages/en/index.php

<?php
$l['Cancel'] = 'Cancel';
?>

 

languages/de/index.php

<?php
$l['Cancel'] = 'Abbrechen';
?>

 

and i cannot do that with a mysql database. im sure that will most definitely kill my server.

 

and i think its efficient the way i do. but i just thought, maybe i have to split it up. certain TEXT that appears only on CERTAIN pages, and common words such as 'cancel', 'okay' or whatever, to put all those into the INDEX.php ...and text that is not so common in the PAGENAME1.php, PAGENAME2.php files

 

and then have a page file, like:

 

<?php
include 'languages/en/index.php';
include 'languages/en/pagename1.php';
?>

 

or MAYBE it doesnt even matter, if its a huge file.. i dunno. im just viewin it on my localhost server, but i dun really notice any long page loads. but its only me on that site. so... if there are more users, i dun know what will happen ..i just wanted to know what would be the best way to do it.

 

but obviously, no one has ever worked with diff. language files lol i just thought maybe someone has, and could give me a few hints on how to do it.

but thanks anyway, haku;) appreciate ya help.

What you are trying to do is use a text file as a database. A database is simply storage for data that is not saved in the script itself. Thats exactly the same purpose your text file is doing - storing data that isn't saved in the script itself. But databases are more efficient then text files.

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.