Add category to translations #43338
Unanswered
fabiomlferreira
asked this question in
Ideas
Replies: 1 comment 3 replies
-
I appreciate the requirement (though I might argue that using Modules might have been a solution if you had considered backend and frontend as separate modules from the start), but I do not think the solution is either elegant or will work. I am also a little concerned about We could instead do:
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In some projects its very important to categorize translations, for example to differentiate translations from backend and frontend.
At the moment the way to do it is something like this __('frontend.Next'), but with this type of translations we cannot write it immediately on english because if we don't translate it on the english translation file we will get "frontend.Next" instead of only "Next".
This is a really issue many other frameworks handle this in a different way for example having a extra parameter to categorize, something like t('frontend', 'Next') unfortunately this is not an option on Laravel because it's a breaking change.
So I think a little and I find a better options we can keep using translations like before but set some "reserved words" on config/app.php something like
translations_reserved_words=['frontend', 'backend'] and in get function from Illuminate\Translation\Translator if the string that will be returned starts by 'frontend.' or 'backend.' we remove it.
So in the example above even if we don't have an english translation for 'frontend.Next' it will allways print only 'Next' if the 'frontend' key is on the translations_reserved_words array.
I think this is a good approach because is something optional if the translations_reserved_words is empty it works exactly as before.
What did you think about it?
Beta Was this translation helpful? Give feedback.
All reactions