take info from url

allofus

New Member
Messages
183
Reaction score
2
Points
0
Hi,

I want to have a list of info

langs.php

array langs
GB = Hello, Red,
FRE = Bonjour, Rouge

stored in an array on a file

www.siteurl.com/lang=GB

The array then being used to populate a page that has several pieces of content that are translated

So for GB it says Hello and down the page the word Red appears and for French it says Bonjour and the word Rouge appears.

<?php include("<?php echo $lang ?>/hello.php"); ?>

<?php include("<?php echo $langs ?>/colour.php"); ?>


or

siteurl.com?lang=GB
<body>
<div id="hello">
<?php echo $lang1 ?>
</div>

<div id="colour">
<?php echo $lang2 ?>
</div>
</body>



I have searched and searched for help with this simple task but I do not know what to search for so I am stumped.

Please help.
Edit:
p.s this needs to be done without using mysql database, just a seperate file with array/s
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
Simple Machines Forum uses this exact same method to achieve multi-language installations of their forum. They create a massive array called $txt and fill it with every single piece of text on the site, then call it up when generating output. It would look something like this:

Code:
GB.txt.php
<?
$txt['the_color_red'] = 'red';
$txt['hello_message'] = 'hello';
?>

FRE.txt.php
<?
$txt['the_color_red'] = 'Rouge';
$txt['hello_message'] = 'Bonjour';
?>

Then, you dynamically include either txt.php file based on the user's preference, in your case, it's a $_GET variable:

Code:
index.php
<?
if(isset($_GET['lang'])) {
     include($_GET['lang'] . '.txt.php');
}
else {
     include('GB.txt.php');
}

echo "<body>
<div id="hello">
$txt['hello_message']
</div>

<div id="colour">
$txt['the_color_red']
</div>

You can see with this system it is very easy to add any language with any number of strings.
 
Last edited:

allofus

New Member
Messages
183
Reaction score
2
Points
0
thanks so much

<body><?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>
<?php echo $lang; ?>

I should be able to use this to get the users preference language, I tested it and it works, but when I try to add the echo inside <php include it does not work.

I will try to put this all together and see whether I get wrapped up in errors.



FYI

I am / My friends and I are working on a website that can be downloaded and installed on any server to assist us with organising an 'International Freedom Event'


When the site is ready I will publish the url here so you all can support the event. Top Secret atm though, lol.

Will be ready in a month or so.

again,
Thanks garretroyce
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
It's a good idea to take the default language from the user's browser, but I think you should also consider having some way for the user to change it. If someone uses a public computer or their browser is set incorrectly, they won't be able to use your site.
 

allofus

New Member
Messages
183
Reaction score
2
Points
0
*************************

Code:
<body>
<?php $langz = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>
<?php echo $langz;?>
<? if(isset($_GET['lang'])) {
   include('/content/lang/' . $_GET['lang'] . '_txt.php');
}
else {
     echo ['$langz'] . '_txt.php');
	 }
else {
     include('content/lang/en_txt.php');
	 } ?>


some static content here .......


<h1>

<?php echo $txt['home_h1']; ?>

</h1>
</body>


when I remove this line;

Code:
}
else {
     echo ['$langz'] . '_txt.php');
	 }

the script works,

but only for the default language en_txt.php
Edit:
ok, the script works fine without the echo $langz

www.siteurl.com/?lang=fr
www.siteurl.com/?lang=en
Edit:
yes garrett,

to change the language there will be a row of flags at the top of the page.

This will then switch all subsequent links to echo the appropriate language.


I want to just have 1 page as a framework for the dynamic content.


reducing coding and file numbers because the site is to be offered as a download for replication purposes.
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
I think I found a few errors, maybe this will help:

Code:
<body>
<?php 
$langz = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); // you don't need the extra <?php ?> tags. Once you're "in php mode" you don't need to cancel and start again every line
echo $langz;
if(isset($_GET['lang'])) {
   include('/content/lang/' . $_GET['lang'] . '_txt.php');
}
// you can only have one 'else' per 'if' block
/* else {
     echo ['$langz'] . '_txt.php'); // this syntax is incorrect maybe you want echo "{$langz}_txt.php" ? this will echo EN_txt.php if the language is EN
	 } */
else {
     include('content/lang/en_txt.php');
	 } 
?>


some static content here .......


<h1>

<?php echo $txt['home_h1']; ?>

</h1>
</body>
 

allofus

New Member
Messages
183
Reaction score
2
Points
0
Thsnks,

I now have a working website, the homepage presents the visitor with a series of flags (18 languages) but the default language is English. Once leaving the home page the flags are no longer present.

The site is no way near finished, but I now have a working framework that is ready for the content to be populated and then translated.

I decided to opt against using the browser language, firstly because I could not get the darned thing to work, but also because I think it better for the visitor to have the ultimate control.


Thanks for your help garretroyce



************************************************************



The 4ALLofUS Team, and others are working on an Internation Event /s focusing on 'Freedom' and help is needed.

We need translators for the following languages.

Mandrin
English
Hindi
Spanish
Arabic
Russian
Portuguese
Bengali
Malay
French
Japanese
German
Farsi
Punjabi
Turkish
Thai
Italian
Korean

The material to be translated from English has not yet been compiled but if you or someone you know is fluent in any of these languages please volunteer your services so we can 'cross that one off of the list'

Thanks,

MattG - broitishnproud

email : mattg [at] 4allofus.com



************************************************************
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
I speak some pretty mean english. So, if you need a USA translation from the UK version, I'm your man!

colour -> color

Anything I'm missing? :p
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Depending on the difficulty of what's being translated, I may be able to help you with the French Translation. I can always ask my teacher for help. :)
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Same here as leafypiggy, although, since French is my mother tongue, I should be able to translate anything.

Also remember to always sanitize your data!
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
allofus, you might want to make a new thread so more people can know about this since we're officially off topic now ;)
 

allofus

New Member
Messages
183
Reaction score
2
Points
0
thanks guys, I will come back to the thread when I have the data that needs translation.

I should point out that all is volunteer based where 4ALLofUS is concerned and there are no financial gains to be made by us, not a single advert or revenue stream so any involvement will be voluntary, but duly credited.


The site is to encourage an 'International Freedom Event. The wording shall be minimal and empowering. The basic idea is to have a website that can be downloaded and installed in a specific sub-directory on any domain of a group / organisation / individual who wishes to support the event and wider movement.

The website will have info about the events, resources to assist with expression and support and a download that features all the above.

There will also be a self populating list of all domains that are hosting the pack if that is ever figured out and a small embedded dormant file that will be used to give notice when pack 2 is available.

ALL in the name of freedom and unity.

If we pull this off in the manner we hope you might just see a lot of people acting in the name of freedom some time soon. The specifics are still a tad 'secret' due to not being ready for public consumption but all will become clear soon with the launch of the first website in July.

again,

Thanks for offering to help.

Maybe send me an email so we can keep the lines of communication open in private,

Respectfully,
MattG - britishnproud.
 
Top