shaggyz / laravel-gettext

Adds localization support to laravel applications using PoEdit and GNU-Gettext.
186 stars 110 forks source link

Translate routes i.e. /about-us in en_US and /om-os in da_DK #59

Closed simplenotezy closed 6 years ago

simplenotezy commented 8 years ago

How could that be possible?

shaggyz commented 8 years ago

Something like this may work (not tested):

Route::get('/' . _('about-us'), function(){
    ...
});

Please let me know if it does

simplenotezy commented 8 years ago

If I have the following route:

    Route::get('/' . _('Classes'), function() {
        echo 'hi ' . _('Classes');
    });

I can only access it through "Classes", but when I hit the route, it will show the translated string of "Classes".

ihoru commented 8 years ago

You didn't change current locale before calling "Route::get".

simplenotezy commented 8 years ago

@ihoru true, but what does that change?

simplenotezy commented 8 years ago

True, following works:

    \LaravelGettext::setLocale('da_DK');
    Route::get('/' . _('Classes'), function() {
        echo 'hi ' . _('Classes');
    });

But I guess the way the package is setup is to be set through middleware, right?

simplenotezy commented 8 years ago

Translatable routes is something that could make this package really strong IMO. The biggest difficulity right now, as I see it, is a clean & proper way to translate routes, and the option to choose between two main setups:

Setup 1 (prefix): http://domain.com/en/about-us
Setup 2 (subdomain): http://en.domain.com/about-us

With the posibility of having the prefix/subdomain optional for the default language: http://domain.com/about-us (for english).

This package is about it, regarding prefix: https://github.com/mcamara/laravel-localization but really lacks a posibility to have setup 2 with optional default language.

I think a solution could be some kind of regular expression constraits: https://laravel.com/docs/5.1/routing#parameters-regular-expression-constraints or maybe https://laravel.com/docs/5.2/routing#route-model-binding