Laravel Translation for Subfolders
1 min read

Laravel Translation for Subfolders

How to access translation from sub folders in Laravel

I organized my language translation folder in Laravel in this way

- resources	
	- de	
    - en		
    	- app.php		
        - subfolder			
        	- file.php

To access the translation keys in app.php, it's straightforward as described in the Laravel documentation. To access a key from app.php, you can use:

trans('app.key')

Once I organized the language translations inside a sub-folder, I tried to access in this way.

trans('subfolder.file.key')

And it wouldn't work. Laravel documentation does not seem to mention how one can access a key from inside a sub folder. I looked up on Github Issues on the Laravel Repository and found a way to access the key.

trans('subfolder/.file.key')

This worked out well but the point to notice is that Taylor confirmed that this is not a way that may be supported in the future releases.