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.
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.
try this:
$loader = app('translator')->getLoader(); $locale = Config::get('app.locale'); $lines = $loader->load($locale, 'messages', '*'); foreach ($lines as $key=>$value){ print($key . ":" . $value); }