devict / votelocal

A web app for receiving local voting information via SMS
15 stars 16 forks source link

Language Toggle #46

Closed imacrayon closed 5 years ago

imacrayon commented 5 years ago

Added a language toggle to the main navigation.

sethetter commented 5 years ago

Just needs a merge from master then this is good to go!

imacrayon commented 5 years ago

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:

sethetter commented 5 years ago

Do the routes have to be dynamically generated? Or could we just loop through config.locales and register them for each?

imacrayon commented 5 years ago

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.

sethetter commented 5 years ago

I know it's generally bad practice, but tests can come later too. Small side projects like this deserve a little leniency.

sethetter commented 5 years ago

Whenever you're happy with it, feel free to merge!