什么是 Php gettext 扩展的最简单的 PHP 替代品,它可以被所有类型的免费托管支持
我正在使用 Zymic,它是一个很棒的托管,但它不支持 php gettext 扩展< /强>。我打算将来购买一些主机,但从现在开始我想要最简单的解决方案来替换 gettext 的功能,在这种情况下我想显示不同的文本无需对文件进行太多修改(至少不必为每种语言创建单独的文件)。
我尝试了这样的操作:
<?php
$lang = "";
switch ($lang) {
case "en":
$lang = "Hello World";
break;
case "es":
$lang = 'Hola Mundo';
break;
}
?>
<div>
<p><?php echo $lang;?></p>
</div>
当我更改 $lang
变量时,它会起作用。我是 PHP 初学者,我想不出一种方法在浏览器中更改它(通过单击链接)。
或者有更好的方法吗?
I'm using Zymic, its a great hosting but it doesn't support the php gettext extension. I'm planning to buy some hosting in the future, but from now I want the simplest solution in order to replace the function of gettext, in this case I want to display different text (English, Spanish, Chinese, etc...) without modyfing the file too much (at least not having to create seaprated files for each language).
I tried something like this:
<?php
$lang = "";
switch ($lang) {
case "en":
$lang = "Hello World";
break;
case "es":
$lang = 'Hola Mundo';
break;
}
?>
<div>
<p><?php echo $lang;?></p>
</div>
When I change the $lang
variable it works. I'm a PHP beginner and I can't think of a way to make it change in the browser (by clicking a link).
Or is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说 Zend_translate 是非常好的如今国际化的最佳选择。它甚至比 gettext 更好。有关许多参数,请参阅这个SO问题。 这个问题是我的方式我自己学习了 Zend_translate。
对于您在问题中展示的简单任务来说,这有点太多了,一开始可能需要一些工作才能适应它,但是 Zend 组件承诺为各种国际化问题提供非常好的解决方案 - 这些问题是不仅仅是翻译单词。还有不同的编号格式、时间格式、货币格式、时区……在国际化应用程序时都需要注意。
它不需要任何特定的扩展,您可以将 Zend Framework 的一部分用作简单的库,无需遵守特定的应用程序结构或任何东西。
I would say Zend_translate is the very best bet for internationalization these days. It's even better than gettext. See this SO Question for a number of arguments. This question was how I myself learned of Zend_translate.
It is a bit much for the simple task you show in your question, and it may be take a bit of work to get used to it in the beginning, but the Zend components promise very good solutions to all kinds of internationalization issues - which are more than just translating words. There are also different numbering formats, time formats, currency formats, time zones... all to be taken care of when internationalizing an application.
It doesn't require any specific extensions, and you can use parts of the Zend Framework as a simple library, there is no need to adhere to a specific application structure or anything.
这一定是我提供过的最古老的答案之一,但是...
PHP-gettext at https:// launchpad.net/php-gettext 是迄今为止最简单的 gettext 替代品。
我在一些项目中使用过,在使用 PHP 获取 gettext 时遇到了麻烦。
This must be one of the oldest answers I've ever supplied, but...
PHP-gettext at https://launchpad.net/php-gettext is by far the simplest workhose as gettext replacement.
I've used in some projects I've had troubles getting gettext working with PHP.