Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:04:09+00:00 2026-06-13T23:04:09+00:00

Hi i am devloping sample site in php i need to translate whole website

  • 0

Hi i am devloping sample site in php i need to translate whole website in to persian. how can it possible in php?? I have tried using the following code.. This code will working fine for deutsch conversion.

1. class.translation.php

<?php
class Translator {

    private $language   = 'en';
    private $lang       = array();

    public function __construct($language){
        $this->language = $language;
    }

    private function findString($str) {
        if (array_key_exists($str, $this->lang[$this->language])) {
            echo $this->lang[$this->language][$str];
            return;
        }
        echo $str;
    }

    private function splitStrings($str) {
        return explode('=',trim($str));
    }

    public function __($str) {  
        if (!array_key_exists($this->language, $this->lang)) {
            if (file_exists($this->language.'.txt')) {
                $strings = array_map(array($this,'splitStrings'),file($this->language.'.txt'));
                foreach ($strings as $k => $v) {
                    $this->lang[$this->language][$v[0]] = $v[1];
                }
                return $this->findString($str);
            }
            else {
                echo $str;
            }
        }
        else {
            return $this->findString($str);
        }
    }
}
?>

2.Register.php

<?php
require_once('class.translation.php');

if(isset($_GET['lang']))
    $translate = new Translator($_GET['lang']);
else
    $translate = new Translator('en');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title><?php $translate->__('CSS Registration Form'); ?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15"/>
        <link rel="stylesheet" type="text/css" href="css/default.css"/>
    </head>
    <body>    
        <form action="" class="register">
            <h1><?php $translate->__('Registration'); ?><a class="flag_deutsch" title="deutsch" href="register1.php?lang=de"></a><a class="flag_english" title="english" href="register1.php"></a></h1>
            <fieldset class="row1">
                <legend><?php $translate->__('Account Details'); ?></legend>
                <p>
                    <label><?php $translate->__('Email'); ?> *</label>
                    <input type="text"/>
                    <label><?php $translate->__('Repeat email'); ?> *</label>
                    <input type="text"/>
                </p>
            </fieldset>

            <div><button class="button"><?php $translate->__('Register'); ?> &raquo;</button></div>
        </form>
    </body>
</html>

Is it possible to transilate to other laguages using this code?? I changed register1.php?lang=de to register1.php?lang=fa(persian).. But nothing hapens..anybody plese help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:04:09+00:00Added an answer on June 13, 2026 at 11:04 pm

    AS per me you can try this method.This method is already implemented in our system and it is working properly.

    Make php file of each language and define all the variables and use those variables in pages.

    for e.g
    For english

    english.php

    $hello="Hello";
    

    persian.php

    $hello=html_entity_decode(htmlentities("سلام"));
    

    Now use this variable to page like this.

    your_page.php

    <label><?php echo $hello; ?></label>
    

    You have load specific language file as per get language variable from URL.

    It is better that you have define this language variable into config file.

    config.php

    if(isset($_GET['lang']) && $_GET['lang']=='persian')
    {
       require_once('persian.php');
    }
    else
    {
       require_once('english.php');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a website using static HTML/CSS. I can put in a PHP
Am developing a sample application for some administration activities. I need to know how
I have been developing a sample application after reading Rails 3 Tutorial book. In
I am currently developing my program using sample BluetoothChat program on android device. This
I am just developing a sample php page.. to display tweets, for a particular
I'm developing a very simple PHP upload feature in my site to permit users
I have 2 scripts running on a site I am developing and one is
(Programming Language: PHP v5.3) I am working on this website where I make search
I am developing a site using pinax. In one of my templates I am
I am developing a script using PHP to save a file to desktop as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.