简体   繁体   English

使用多种自然语言最有效的方式

[英]Most effective way working with multiple natural languages

I am currently working with a codeigniter PHP based application and have come to the point where it's about to go off with multiple languages. 我目前正在使用基于codeigniter PHP的应用程序,并且已经达到了即将推出多种语言的程度。

Is codeigniters own language class the most effective way to handle languages? codeigniters自己的语言类是处理语言最有效的方法吗? Is there any specific language-tools/libraries that are commonly used in PHP apps? 是否有任何特定的语言工具/库在PHP应用程序中常用?

Thanks! 谢谢!

I've never used CI_Language but it appears to use language arrays to do the translation. 我从未使用过CI_Language,但它似乎使用语言数组来进行翻译。

Overly simplified example of this type method: 这种类型方法的简化示例:

$trans = array(
    'MAIN_TITLE' => 'Title Here'
);

echo $trans['MAIN_TITLE'];

Personally I find this really annoying because you're then editing views that are cluttered with array key names instead of useful text. 我个人觉得这真的很烦人,因为你正在编辑那些杂乱的数组键名而不是有用文本的视图。 Which can be quite annoying at times. 有时这可能很烦人。 Not to mention you have to remember which keys correlate to which strings if you are using them in multiple places. 更不用说如果你在多个地方使用它们,你必须记住哪些键与哪些字符串相关。

I use Gettext which I find much easier. 我使用Gettext ,我觉得更容易。 You just have to wrap your strings with the translate method: _() . 你只需要使用translate方法包装你的字符串: _() Then once you're done with your app, you open up PoEdit and create the new language file. 然后,一旦完成了应用程序,就可以打开PoEdit并创建新的语言文件。 PoEdit will parse all of my source files looking for strings wrapped like this <?php echo _('Title here') ?> and insert them into the .po language file. PoEdit将解析我的所有源文件,寻找包含这样的字符串<?php echo _('Title here') ?>并将它们插入到.po语言文件中。 You can then go string by string and translate the text easily within PoEdit. 然后,您可以逐字逐句地转换,并在PoEdit中轻松翻译文本。 The benefit of this is you have the source translation right there within PoEdit, instead of a meaningless array key name in some include file 这样做的好处是你在PoEdit中有源转换,而不是在某些包含文件中有一个无意义的数组键名

This all makes my life much easier in that I can update my language files every Friday with one click. 这一切都让我的生活变得更轻松,因为我可以每周五更新我的语言文件,只需点击一下。 Any new or modified translations will automatically be added to my language file, and any unused translations will automatically be removed. 任何新的或修改过的翻译都将自动添加到我的语言文件中,并且将自动删除任何未使用的翻译。 I send the files off to my 3 international branchs for translation, and my changes and updated language files are ready to be deployed Monday morning 我将文件发送到我的3个国际分支机构进行翻译,我的更改和更新的语言文件已准备好在星期一早上部署

You may want to have a look into php intl library. 你可能想看看php intl库。 http://php.net/intl http://php.net/intl

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

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