Closed imacrayon closed 5 years ago
Just needs a merge from master then this is good to go!
I can't find a way to write tests for this translation stuff though :disappointed: PHPUnit fakes HTTP requests in a weird way where the Request
object doesn't get build up until middleware runs, but we have to check the request before the middleware so we can dynamically create the routes in /routes/web.php
. The Request
is all ready to go as soon as the framework boots up in a normal server environment but not when running tests :man_shrugging:
Do the routes have to be dynamically generated? Or could we just loop through config.locales
and register them for each?
They don't have to be dynamically generated but if we use a loop, each route would need a unique name like archive.en
& archive.es
then things get messy when you want to link to a page using the route name.
I did find one solution where you could override the route()
helper to handle the currently set locale. Basically when you pass it a route name it would append the locale code to the end of the name before loading the route. I was trying to avoid have to hacking core helpers like that but it might be worth it if testing works.
I know it's generally bad practice, but tests can come later too. Small side projects like this deserve a little leniency.
Whenever you're happy with it, feel free to merge!
Added a language toggle to the main navigation.