Currently I'm doing this in a service provider and it works, but that doesn't seem to me like the "proper" place to do it.
@JussiMannisto Nope, the boot() method of a service provider is the proper place to register a language namespace :)
Namespaces for resources like language files and views are for more “packages”, so if you had a package that added a blog to your application then you may register a blog:: namespace and access translations like trans('blog::messages.posts').
If you have both an API and a CMS, then you might create a package for your application that has its own service provider, and you have translations specific for your application that you load in there:
<?php // vendor/package/src/PackageServiceProvider.php
namespace Vendor\Package;
class PackageServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app['lang']->addNamespace('package', __DIR__.'/../resources/lang');
}
}
Then like Laravel, you would store your translations in a resources/lang/{locale} directory, at the same level as your src directory:
- /resources
- /lang
- /en
- /messages.php
- /es
- /messages.php
- /en
- /views
- /lang
- /src
- /Console
- /Commands
- /Http
- /Controllers
- PackageServiceProvider.php
- /Console