+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: take info from url

  1. #1
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    take info from url

    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 by allofus; 05-18-2009 at 12:05 AM. Reason: Automerged Doublepost

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: take info from url

    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 by garrettroyce; 05-18-2009 at 06:38 AM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Re: take info from url

    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

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: take info from url

    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.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Re: take info from url

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

    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 by allofus; 05-18-2009 at 01:36 PM. Reason: Automerged Doublepost

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: take info from url

    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>
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Thumbs up Re: take info from url

    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



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

  8. #8
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: take info from url

    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
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  9. #9
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: take info from url

    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.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  10. #10
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: take info from url

    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 by xav0989; 05-21-2009 at 04:03 PM.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Account Info Reset
    By shwacker in forum Free Hosting
    Replies: 0
    Last Post: 01-25-2009, 05:11 AM
  2. MySQL Database login info
    By handsolo in forum Free Hosting
    Replies: 1
    Last Post: 06-27-2008, 07:32 PM
  3. Account Info Is Incorrect
    By darkguild in forum Free Hosting
    Replies: 5
    Last Post: 03-05-2008, 12:23 AM
  4. My account info was changed
    By SEŅOR in forum Free Hosting
    Replies: 11
    Last Post: 10-18-2006, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers