PHP - 如何将网站翻译成多种语言?

PHP - how to translate a website into multiple languages?(PHP - 如何将网站翻译成多种语言?)
本文介绍了PHP - 如何将网站翻译成多种语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目前是英文的网站;当用户单击不同的语言时,我希望能够切换到不同的语言(网站上几乎没有国家标志图标).我目前正在尝试的方式是使用数组,例如:

I have a website that's currently in English; I want to be able to switch to a different language when a user clicks on a different language (there are little country flag icons on the site). The way I'm currently trying is with arrays, e.g.:

$english = array('index',
           array('h1' => 'this is some h1 text', 
                 'h2' => 'this is some h2 text'));

$japanese = array('index',
            array('h1' => '世界交換への歓迎',
                  'h2' => 世界交換への'));


print $english[index][h1];
print $japanese[index][h2];

如您所见,如果我以单独的语言为每个页面都这样做,那将是大量的代码.我还可以尝试什么其他方法?

As you can see, if I did this for every single page in a separate language, it would be an insane amount of code. What other method can I try?

推荐答案

鉴于您正在寻找最终将导致 l10n 支持的完整 i18n 支持,我建议您在支持这些内容的 PHP 框架中编写您的页面盒子.

Given that you are looking for full i18n support which will eventually lead to l10n support, I would suggest writing your page in a PHP framework that supports these things out of the box.

就我个人而言,我只使用 Symfony 框架进行过翻译.他们将数据库中的 i18n 表扩展名组合用于内容,并将 XLIFF 文件用于界面翻译.它在设置后相当透明,并且使用框架避免了手动编写所有这些支持.

Personally I've only done translations with the Symfony framework. They use a combination of i18n table extension in the DB for content, and XLIFF files for translations of the interface. It was fairly transparent once it was setup, and using a framework avoids having to write all this support by hand.

我也知道 Zend、CakePHP 和 Code Igniter 都支持 i18n.

I also know that i18n is supported in Zend, CakePHP, and Code Igniter.

这篇关于PHP - 如何将网站翻译成多种语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)