Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

donald.tbd's avatar

Laravel 5.4 - get translations from database instead of lang files

I need to keep my translations in a database. I have created a model with group, key and value and filled the database with all the values i currently have in my lang files. Now i wish to make the switch so if trans('group.key') or @lang('group.key') is called from my code i want it to get the value from database, not the lang file. How is it possible to achieve this?

PS. I looked through some of the available plugins that do something similar, but they dont quite fit me because i have my own complex models.

0 likes
2 replies
SapporoGuy's avatar

I used a modified settings package back in L4.x. You should also consider caching the inital db call to make this faster too.

I used to be real big on this type of functionality until I realized that language files just don't change that often.

Are you planning to let people do their own translations?

donald.tbd's avatar

Yes, the backend users need to be able to add languages and translate the whole page to a new language. Giving them lang files in php array format would cause chaos i think. Its even hard to keep them in sync myself when i have 3 languages.

One thing im concidering at the moment is to generate language files on each change (or if it turns out to be too heavy an operation then make a seperate button for users to propagae language change). This way I wont have to worry about how to hijack laravels native translator and also i wont need to make db querys and caching for each user.

What do you guys think of this solution?

Please or to participate in this conversation.