来源:http://trac.seagullproject.org/wiki/Howto/Internationalisation

I18N: 国际化

Seaull让翻译应用程序的图形用户界面非常容易。请看:Howto/Internationalisation/TranslatingModules。管理员可以根据用户的区域来自定义时间/日期/数字的格式。如地理位置。

支持的语言

Translations

现在的语言设计是保存在一个session变量中,所以可以在页面之间或session基础上转换。

非英语站点

如果你想用捷克语言包取代默认的英语包,那么

  • 以member身份登陆,编辑你的外观,并将捷克语设置为你的界面语言
  • 以admin身份登陆,单击'Users and Groups',然后选择'preferences'设置整个站点的默认语言偏好选项。

语言文件

所有的要翻译的字符串被保存成易于管理语言文件,包含一个简单的PHP数组:

    $words = array(
/*  FAQ */
        'FAQs' => 'FAQs',
        'FAQ Manager' => 'FAQ Manager',
        'FAQ Manager :: Browse' => 'FAQ Manager :: Browse',
        'Please fill in a question' => 'Bitte geben Sie eine Frage ein',
        'Please fill in an answer' => 'Bitte geben Sie die dazugehörige Antwort ein',
 
        'Question' => 'Frage',
        'Answer'   => 'Antwort',
 
        'FAQ ID'   => 'FAQ ID',
        'Date created' => 'Erstellungsdatum',
 
        ''list
        'Questions' => 'Fragen',
        'Answers' => 'Antworten',
    );

通过语言参数来转换语言

POST或GET都可以用来请求。你下面的URI这样传递语言参数来转换:

http://example.com/about/?lang=ru-windows-1251

模板中字符串的翻译

开发人员不应该在managers中翻译字符串,而应该在模板中翻译。

<tr>
    <th align="left">{translate(#Question#)}:</th>
    <td>
        <div class="error" flexy:if="error[question]">
            {translate(error[question])}
        </div><textarea cols="40" rows="4" name="faq[question]">{faq.question}</textarea>
    </td>
</tr>

用下列代码

{translate(pageTitle)}

来翻译传递给$output的变量和下列代码

{translate(#Question#)}

来翻译模板中的文本(e.g. for the GUI)

本地化

默认Seagull会提供基本的PHP local功能,如,你可以在你的代码中调用像strftime()这样的PHP函数,这些函数可以被设置的locale修改。

要使用高级的locale处理功能,先进入到Config界面然后选择:

General Site Options -> Extended locale support -> On

这将Seagull和PEAR的I18Nv2库集成在一起,使用方法:

<code>$locale =& SGL_Locale::singleton();

echo $locale→formatCurrency(2000,I18Nv2_CURRENCY_LOCAL); echo $locale→formatDate(time()); </code>

请看 /trunk/lib/SGL/Locale.php 来看个体实现方法。

在Config界面中, 'localeCategory'是可配置的,默认是设置成LC_ALL,它支持a。但是欧洲用户喜欢改成LC_TIME,因为数字分隔符会导致计算问题。

时区hack

翻译导航栏

要翻译导航栏等需要将翻译保存在数据库内,即不使用文件保存翻译。

 
howto/internationalisation.txt · 最后更改: 2010/05/30 00:21 (外部编辑)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2