Welcome Guest, Not a member yet? Register   Sign In
Add a global function to return the default locale
#1
Smile 

I would really love it a miscellaneous global function to fetch the default locale could be added on the framework.
This will avoid writing such code statements:
Code:
$appConfig = new \Config\App();
$dateToday = Time::today(app_timezone(), $appConfig->defaultLocale);
Reply
#2

You can write it as follows:
PHP Code:
$dateToday Time::today(); 

Because the default locale is used by default.

If you really want to get it, you can use PHP's Locale::getDefault().
Reply
#3
Thumbs Up 
(This post was last modified: 02-24-2024, 06:37 AM by Elvis254.)

(02-23-2024, 06:01 PM)kenjis Wrote: You can write it as follows:
PHP Code:
$dateToday Time::today(); 

Because the default locale is used by default.

If you really want to get it, you can use PHP's Locale::getDefault().

Here is the solution.
Code:
rtrim(slash_item('defaultLocale'), '/')

Routing currently includes locale because its negotiated. Anyway thanks.

(02-24-2024, 06:22 AM)Elvis254 Wrote:
(02-23-2024, 06:01 PM)kenjis Wrote: You can write it as follows:
PHP Code:
$dateToday Time::today(); 

Because the default locale is used by default.

If you really want to get it, you can use PHP's Locale::getDefault().

Here is the solution.
Code:
rtrim(slash_item('defaultLocale'), '/')

Routing currently includes locale because its negotiated. Anyway thanks.

Another solution of getting configurations is using the new settings library as shown below.
This one marks the best solution of the problem I was facing yesterday. Am done writing the system. Thanks a lot CodeIgniter Team.

Code:
setting('App.defaultLocale')
Reply
#4

Ah, you want to get the default locale set in Config\App even if content negotiation is done.

PHP Code:
config('App')->defaultLocale;
$this->request->getDefaultLocale(); 
Reply
#5

(02-24-2024, 04:55 PM)kenjis Wrote: Ah, you want to get the default locale set in Config\App even if content negotiation is done.

PHP Code:
config('App')->defaultLocale;
$this->request->getDefaultLocale(); 
Yes, this is what I wanted let me update the code I will use the second statement i.e. get it from the request.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB