mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.36k stars 512 forks source link

Laravel API routers got 404 #862

Open beshoo opened 1 year ago

beshoo commented 1 year ago
 'supportedLocales' => [

        'en'          => ['name' => 'English',                'script' => 'Latn', 'native' => 'English', 'regional' => 'en_GB'],
        'ar'          => ['name' => 'Arabic',                 'script' => 'Arab', 'native' => 'العربية', 'regional' => 'ar_AE'],

    ]

    // If `hideDefaultLocaleInURL` is true, then a url without locale
    // is identical with the same url with default locale.
    // For example, if `en` is default locale, then `/en/about` and `/about`
    // would be identical.
    //
    // If in addition the middleware `LaravelLocalizationRedirectFilter` is active, then
    // every url with default locale is redirected to url without locale.
    // For example, `/en/about` would be redirected to `/about`.
    // It is recommended to use `hideDefaultLocaleInURL` only in
    // combination with the middleware `LaravelLocalizationRedirectFilter`
    // to avoid duplicate content (SEO).
    //
    // If `useAcceptLanguageHeader` is true, then the first time
    // the locale will be determined from browser and redirect to that language.
    // After that, `hideDefaultLocaleInURL` behaves as usual.
    'hideDefaultLocaleInURL' => false,

    // If you want to display the locales in particular order in the language selector you should write the order here.
    //CAUTION: Please consider using the appropriate locale code otherwise it will not work
    //Example: 'localesOrder' => ['es','en'],
    'localesOrder' => [],

    //  If you want to use custom lang url segments like 'at' instead of 'de-AT', you can use the mapping to tallow the LanguageNegotiator to assign the descired locales based on HTTP Accept Language Header. For example you want ot use 'at', so map HTTP Accept Language Header 'de-AT' to 'at' (['de-AT' => 'at']).
    'localesMapping' => [],

    // Locale suffix for LC_TIME and LC_MONETARY
    // Defaults to most common ".UTF-8". Set to blank on Windows systems, change to ".utf8" on CentOS and similar.
    'utf8suffix' => env('LARAVELLOCALIZATION_UTF8SUFFIX', '.UTF-8'),

    // URLs which should not be processed, e.g. '/nova', '/nova/*', '/nova-api/*' or specific application URLs
    // Defaults to []
    'urlsIgnored' => ['/skipped'],

    'httpMethodsIgnored' => ['POST', 'PUT', 'PATCH', 'DELETE'],

My Router api.php


Route::group(['prefix' => LaravelLocalization::setLocale(),
              'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]], function()
{
        Route::get('/cv/{cv_slug}', [CvsController::class, 'ViewCv']);
});

I opened http://127.0.0.1/cv/api/22333 it redirects me to http://127.0.0.1/cv/en/api/22333 with Router not found

I checked https://github.com/mcamara/laravel-localization/issues/382 and https://github.com/mcamara/laravel-localization/issues/482

and I can not make it works!

ghost commented 1 year ago

I have exactly the same issue

GergoKormoczy commented 1 year ago

I don't know if this is the best solution but it is working my case. You should add exception something like this:

'urlsIgnored' => ['/api/*'],

config/laravellocalization.php

beshoo commented 1 year ago

I already set that.... This plugin is not working.....

On Wed, Mar 29, 2023, 5:17 PM Körmöczy Gergő @.***> wrote:

I don't know if this is the best solution but it is working my case. You should add exception something like this:

'urlsIgnored' => ['/api/*'],

config/laravellocalization.php

— Reply to this email directly, view it on GitHub https://github.com/mcamara/laravel-localization/issues/862#issuecomment-1488826834, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLT23KSXQYJLH7AFDYOY3W6RHAXANCNFSM6AAAAAAWABSUKM . You are receiving this because you authored the thread.Message ID: @.***>

GergoKormoczy commented 1 year ago

Then you should run after of course.

php artisan optimize:clear
php artisan route:trans:clear
fahadapps79 commented 1 year ago

add ["Accept": "application/json"] to header of the request