dsg41888 2013-09-30 14:50
浏览 86
已采纳

允许在Laravel中进行前端翻译编辑

In my Laravel application I would like to allow my (super) users to define language translations from the front-end. AFAIK there is no Lang::all() or something like this that provides the list of language variables. I am looking for a way to parse language keys for a language and allow the values to be defined by the end user.

  • 写回答

2条回答 默认 最新

  • douxia1988 2013-10-01 07:22
    关注

    As far as I know you are correct, there isn't any Lang:all()-ish function returning all the registered lang keys.

    If you want to have such ability to list all the registered variables, config may be the way to go - there you are able to fetch a complete list of keys. In my opinion though, that's somewhat a messy solution to substitute lang with config. Even more messy, you could leverage the line replacement mechanism in lang

     echo Lang::get('messages.welcome', array('name' => 'Shakur'));
    

    but ofcourse you'd need to write the rest of you idea around it.

    Instead I guess it's best to DRY your way out of the issue (Dont Repeat Yourself) :) A quick reckon reveals a solution to your problem is already available:

    the waavi/translation package should fit your needs, it's a "translation package for Laravel 4 with database and cache support"

    From the docs:

    Upgrading Laravel's localization module Keeping a project's translations properly updated is cumbersome. Usually translators do not have access to the codebase, and even when they do it's hard to keep track of which translations are missing for each language or when updates to the original text require that translations be revised.

    This package allows developers to leverage their database and cache to manage multilanguage sites, while still working on language files during development and benefiting from all the features Laravel's Translation bundle has, like pluralization or replacement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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