dtpwra8456 2015-07-23 05:14
浏览 34

对于Codeigniter v2.x.x中的Custom Lang.php核心,Helper无法正常运行

Let say the input of my custom language was:

$lang['number.you.got'] = 'Number you got was %1, %2 and %3';

I've modified the Lang.php in /system/core/ codeigniter 2 folder. Here is the code:

function line($line = '')
{
    //get the arguments passed to the function
            $args = func_get_args();

            //count the number of arguments
            $c = count($args);

            //if one or more arguments, perform the necessary processing
            if ($c)
            {
                //first argument should be the actual language line key
                //so remove it from the array (pop from front)
                $line = array_shift($args);

                //check to make sure the key is valid and load the line
                $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];

                // Because killer robots like unicorns!
                if ($line === FALSE)
                {
                        log_message('error', 'Could not find the language line "'.$line.'"');
                }

                //if the line exists and more function arguments remain
                //perform wildcard replacements
                if ($line && $args)
                {
                    $i = 1;
                    foreach ($args as $arg)
                    {
                        $line = preg_replace('/\%'.$i.'/', $arg, $line);
                        $i++;
                    }
                }
            }
            else
            {
                //if no arguments given, no language line available
                $line = false;
            }

            return $line;

}

The modified codes above is to implement the language in the website, let say:

$this->lang->line('number.you.got','number1','number2','number3');

and the output will be

Number you got was number1, number2 and number3

Now, I used language_helper in codeigniter v2

function lang($line)
{
    $CI =& get_instance();
    $line = $CI->lang->line($line);
    $line = '<label>'.$line."</label>";
    return $line;
}

But the result was not the same as I got before.

My expected result that if I can easily use helper lang('number.you.got','number1','number2','number3')...

Anybody can help me?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line