duanqinqian5299 2019-01-18 08:02
浏览 114

语言切换器,如何使用变量回显而不是_lang行的键

I like to store my language lines in variables or array.

And I have this problem. How can I echo $data["menu_production"] instead of $this->lang->line("menu_production");? It works when I echo ($this->lang->line("menu_production");) but not with $data or other variable. In my controller I call this function:

function index() {
  $data["menu_production"] = $this->lang->line("menu_production");
  $this->load->view('menu', $data);
}
  • 写回答

1条回答 默认 最新

  • dra8603 2019-01-18 08:26
    关注

    A quick workaround for this will be using sprintf

    Let your language file has a key something like

    $lang['custom_message'] = "Hello %s!";
    

    Then use the language class as

    echo sprintf($this->lang->line('custom_message'), 'world');
    // output: Hello world!
    
    $name = "John Doe";
    echo sprintf($this->lang->line('custom_message'), $name);
    // output: Hello John Doe!
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度