【问题标题】:i18n (internationalization) in Fuel ViewsFuel Views 中的 i18n(国际化)
【发布时间】:2011-12-05 03:41:22
【问题描述】:

在 Fuel PHP 的视图中处理 i18n(国际化)字符串的最佳/建议方法是什么?我在文档中找不到对此的任何引用,我正在考虑使用gettext。有什么建议吗?

【问题讨论】:

    标签: php view internationalization fuelphp


    【解决方案1】:

    您可以使用the lang class,您可以使用它来加载您需要的语言文件。 代码示例:

    example.php

    return array(
        'hello' => 'Hello :name',
        'something'=> 'something :name!',
        'test'=> array(
            'hello' => 'Hello', 
            'something' => 'Plop'
        )
    );
    

    您的文件

    // Will load the file "example.php" into the "var" variable
    Lang::load('example', 'var');
    
    // Get the variable "something"
    $this->output = Lang::get('var.test.something');
    

    您可以创建不同的语言文件,例如“en, it”或更多,并根据用户的本地设置动态加载文件。

    【讨论】:

    • 日志中的一个改进是使用 Lang::get('var.test.something') 因为 Lang::line() 已被弃用。还有 __() 程序助手。 docs.fuelphp.com/classes/lang.html
    • 嗯,我在文档中搜索“Load::get”,但没有找到。它是否存在于开发分支中的修改?
    • 天哪,我的页面没有加载,所以我只读到加载内容结束-_-...谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 2017-06-09
    • 2012-02-25
    • 1970-01-01
    相关资源
    最近更新 更多