dongtaochan0777
dongtaochan0777
2011-07-06 05:51

网站的多语言支持

已采纳

While trying to modify eyeos install index page to support multi language using gettext method, i was unable to resolve an issue with the index page.

ISSUE:

The index page has 4 steps

It is possible to change the front page to the language we choose

but when i try to click next step it shows the default language rather than the choosen one

and also report an error as "Undefined index: submit in /var/www/html/install/index.php on line 78"

How can i resolve it...

the index.php file is

      <?php
        ob_start();
            if(!isset($_GET['step'])) 
            {
            $step = 'introduction';
           }  
           else 
           {
            $step = basename($_GET['step']);
           }
           require_once('steps/'.$step.'.php');
         echo '<?xml version="1.0" encoding="UTF-8" ?>';
           ?>
             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
             <link rel="stylesheet" type="text/css" media="all" href="style.css"/>
     <title>eyeOS 2 installation</title>
 </head>
 <body>

<form action="" method="post">
    <select name="language">
    <option value="en">English</option>
    <option value="es">Spanish</option>
    </select>
    <input type="submit" name="submit" value="change language"/>
</form>

        <div id="wrapper" class="wrapper">
            <div id="topbar" class="topbar">
                <img src="logo-eyeos.png" id="logo" class="logo" />
                <div id="logotext" class="logotext">
                    <? echo toptext(); ?>
                </div>
            </div>
            <span id="sidebar" class="sidebar">
                <ul class="sidelist">
                    <?php

                        if ($_POST['submit'])
                        {
                            bindtextdomain('messages', './');
                            textdomain('messages');

                            $lang=$_POST['language'];

                            if ($lang)
                            {

                                switch ($lang) 
                                {
                                    case 'es':
                                        putenv('LC_ALL=es_ES'); 
                                        setlocale(LC_ALL,'es_ES');
                                        break;
                                    case 'en':
                                    default:
                                        setlocale(LC_ALL,'en_GB');
                                        break;
                                }
                            }               


                        if($step == 'introduction') {
                            echo _('<li class="selected">Introduction</li>');
                        } else {
                            echo _('<li>Introduction</li>');
                        }

                        if($step == 'requirements') {
                            echo _('<li class="selected">Requirements</li>');
                        } else {
                            echo _('<li>Requirements</li>');
                        }
                        if($step == 'configuration') {
                            echo _('<li class="selected">Configuration</li>');
                        } else {
                            echo _('<li>Configuration</li>');
                        }

                        if($step == 'end') {
                            echo _('<li class="selected">End</li>');
                        } else {
                            echo _('<li>End</li>');
                        }
                        }  

                    ?>
                </ul>
            </span>
            <span id="content" class="content">
                  <?php getContent(); ?>
            </span>
        </div>
</body>

and i edited some line in messages.po file

Lines are

1."Content-Type: text/plain; charset=UTF-8 "

2.

: index.php:81

msgid "Introduction" msgstr "Introducción"

: index.php:83

msgid "

Introduction" msgstr "Introducción"

3.

: index.php:87

msgid "Requirements" msgstr "Requisitos"

: index.php:89

msgid "

Requirements" msgstr "Requisitos"

4.

: index.php:92

msgid "Configuration" msgstr "Configuración"

: index.php:94

msgid "

Configuration" msgstr "Configuración"

5.

: index.php:98

msgid "End" msgstr "Final"

: index.php:100

msgid "

End" msgstr "Final"

2.#: index.php:81 msgid "Introduction" msgstr "Introducción"

: index.php:83

msgid "

Introduction" msgstr "Introducción"
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dosro793520628 dosro793520628 10年前

    To fix the error you report, and also report an error as "Undefined index: submit in /var/www/html/install/index.php on line 78", change:

    if ($_POST['submit'])
    

    to:

    if (isset($_POST['submit']))
    

    2nd issue:

    I would add some debugging to your code to see what the result of $_POST['language'] is. Maybe you aren't catching the language properly in your switch

    点赞 评论 复制链接分享

为你推荐