我知道如何创建 .po 文件以及如何生成 .mo 文件,然后在我的 Codeigniter 支持的网站上使用它们进行翻译。但是,我不太确定如何从站点 GUI 更改语言。我想坚持使用 codeigniter 的默认 url 调用模式:www.domain.com/controllername/method/param1/param2。
像这样调用服务器是显而易见的:www.domain.com/controllername?lang=en
使用默认 url 模式为每个控制器执行此操作,需要我在每个控制器中实现相同的方法,只是为了传递 lang 参数到 setlocale() 函数,然后绑定到我的 .po 域名。感觉很尴尬...
你们有什么想法如何在 codeigniter 中使用 gettext 吗?是的,我确实想使用 gettext。
I know how to create .po files and how to generate .mo files and then use them for translation on my Codeigniter powered site. However, I'm not quite sure on how to change language from the site GUI. I want to stick to codeigniter's default url calling schema: www.domain.com/controllername/method/param1/param2.
Calling the server like this is a no-brainer: www.domain.com/controllername?lang=en
Doing that for every controller using the default url schema, requires me to implement the same method in every controller, just to pass the lang parameter to the setlocale() function and then bind to my .po domain name. Feels awkward...
ANy ideas how you guys work with gettext in codeigniter? And yes, I do want to work with gettext.
发布评论
评论(2)
我只是制作了一个库,它可以自动翻译视图中 {t} 和 {/t} 之间的所有文本,我发布在这里以防有人想使用它而不是在视图中调用 gettext 函数:
http://www .chuongduong.net/page/15/codeigniter-gettext-with-smarty-or-parser-template-without-php-code-in-view.html
视图代码可能是:
I just make a library which can auto translate all text between {t} and {/t} in the view, I posted here in case some one want to use it instead calling the gettext function in the view:
http://www.chuongduong.net/page/15/codeigniter-gettext-with-smarty-or-parser-template-without-php-code-in-view.html
The view code might be:
我检查在“post_controller_constructor”处挂钩检测的用户语言,并将其设置在全局可用的位置(例如,在运行时更改配置文件中的语言)。控制器只需使用该值即可。
通过以下回退检查来检测语言,
但是,如果不支持某种语言,请使用默认语言。
使用新数据设置或刷新 cookie。
因此,您通常不需要使用 GET 参数,甚至在用户单击某处更改语言时只需使用一次
I check for the user's language hooking the detection at "post_controller_constructor", and I set it somewhere globally available (e.g. changing at runtime the language in the config file). A controller has just to use the value.
The language is detected with the following check in fallback
If a language is not supported, however, use the default.
Set or refresh the cookie with the new data.
So you usually do not need to use the GET parameter, evenctuallly just one time if the user clicks somewhere to change language