简体   繁体   English

PHP - ZendFramework:如何在没有整个框架的情况下使用Zend_Translate?

[英]PHP - ZendFramework: How to use Zend_Translate without the whole framework?

i'm building a simple PHP website and want to translate it into 2 languages (spanish,english). 我正在构建一个简单的PHP网站,并希望将其翻译成2种语言(西班牙语,英语)。 I've read some questions here and everybody recommend Zend_Translate. 我在这里读了一些问题,每个人都推荐Zend_Translate。 I've read the documentation and seems pretty good. 我已经阅读了文档并且看起来非常好。

I've read I can use the Zend_Translate component without using the entire Framework, just that component, but i cannot. 我已经读过我可以使用Zend_Translate组件而不使用整个Framework,只是那个组件,但我不能。 I've tryed everything. 我尝试了一切。 I downloaded the framework and placed it in a libs subdirectory. 我下载了框架并将其放在libs子目录中。 And i've tryed severals ways to import it: 我尝试了几种方法来导入它:

// First try
require('libs/Zend/Translate.php'); //Fail

//Second try
require('libs/Zend/Loader.php'); //Good
Zend_Loader::loadClass('Zend_Translate'); //Fail

Can you help me please? 你能帮我吗?

Thanks to this post, I was able to finally make it work! 感谢这篇文章,我终于能够成功了!

For people like me who are searching for a working example of using zend_translate without using the Zend Framework, here it is: 对于像我这样的人在不使用Zend Framework的情况下搜索使用zend_translate的工作示例,这里是:

https://github.com/26medias/zend_translate https://github.com/26medias/zend_translate

If you are using Windows (like I do), you'll need to install gettext first: http://gnuwin32.sourceforge.net/packages/gettext.htm 如果你使用的是Windows(就像我一样),你需要先安装gettext: http//gnuwin32.sourceforge.net/packages/gettext.htm

To edit the translations: 要编辑翻译:

  1. open /locale/[locale name]/messages.po open / locale / [locale name] /messages.po
  2. add your translations 添加您的翻译
  3. Execute translate.bat (if you didn't install gettext in the default directory, update the path to the bin folder). 执行translate.bat(如果未在默认目录中安装gettext,请更新bin文件夹的路径)。 It will generate/update the messages.mo file. 它将生成/更新messages.mo文件。

And you're done! 而且你已经完成了!

You have to put your 'libs' in your include path. 你必须把你的'libs'放在你的包含路径中。 It's quite simple : 这很简单:

set_include_path( implode( PATH_SEPARATOR, array(
                '/path/to/your/libs',
                get_include_path(),
            )
        )
    ); 

Per @santiagobasulto, I'm creating an answer for this question. 根据@santiagobasulto,我正在为这个问题创建一个答案。

Make sure that Zend/ is in your path, as the Zend Framework expects that folder to be there. 确保Zend/在您的路径中,因为Zend Framework期望该文件夹存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM