0

I'm trying to using codeigniter 4 {locale} group.

$routes->group('{locale}', function ($routes){
    $routes->group('customer', function ($routes){
        $routes->match(['get','post'],'/', 'Customer::index');
    });
});

When I accessing to en/customer/ everything good but if i trying to access without locale like this customer/ im getting 404 error.

My default language en i want to do If there is no language in the route, the page should work with the default language.

Şahin Ersever
  • 326
  • 1
  • 8
  • Does this answer your question? [CodeIgniter optional parameter](https://stackoverflow.com/questions/14183231/codeigniter-optional-parameter) – steven7mwesigwa Nov 20 '21 at 06:35

1 Answers1

0

app/config.php


    /**
     * --------------------------------------------------------------------------
     * Default Locale
     * --------------------------------------------------------------------------
     *
     * The Locale roughly represents the language and location that your visitor
     * is viewing the site from. It affects the language strings and other
     * strings (like currency markers, numbers, etc), that your program
     * should run under for this request.
     *
     * @var string
     */
    public $defaultLocale = 'en';

    /**
     * --------------------------------------------------------------------------
     * Negotiate Locale
     * --------------------------------------------------------------------------
     *
     * If true, the current Request object will automatically determine the
     * language to use based on the value of the Accept-Language header.
     *
     * If false, no automatic detection will be performed.
     *
     * @var bool
     */
    public $negotiateLocale = true;

    /**
     * --------------------------------------------------------------------------
     * Supported Locales
     * --------------------------------------------------------------------------
     *
     * If $negotiateLocale is true, this array lists the locales supported
     * by the application in descending order of priority. If no match is
     * found, the first locale will be used.
     *
     * @var string[]
     */
    public $supportedLocales = ['en','fa'];


then use header to chngae languge Accept-Language set To en or fa

paliz
  • 347
  • 2
  • 5
  • `app/config.php` exactly the same as what you wrote. Where can i set Accept-Language in Codeigniter Or should I do this manually? – Şahin Ersever Oct 16 '21 at 09:33
  • use post man first testing app https://www.postman.com/ you add header in request you send – paliz Oct 16 '21 at 18:41