Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidArgumentException: The locale option does not look like a valid locale #67

Closed
madeincosmos opened this issue Apr 25, 2019 · 8 comments · Fixed by #68
Closed

InvalidArgumentException: The locale option does not look like a valid locale #67

madeincosmos opened this issue Apr 25, 2019 · 8 comments · Fixed by #68

Comments

@madeincosmos
Copy link
Contributor

madeincosmos commented Apr 25, 2019

This error is only triggered when intl fails to load:

InvalidArgumentException: The locale option does not look like a valid locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C. For more option install the intl extension. 

The regex here expects locale in format such as en_US.UTF-8 instead of what's given:

https://github.com/rlanvin/php-rrule/blob/master/src/RRule.php#L2084

According to setlocale specs, all these extra parameters will normally be returned for setLocale(LC_ALL, 0), which is called here:

https://github.com/rlanvin/php-rrule/blob/master/src/RRule.php#L2193

To only get en_US.UTF-8 we'll want to use LC_CTYPE instead:

https://www.php.net/manual/en/function.setlocale.php#106811

Applying this change on my test site solved the problem for me.

@rlanvin
Copy link
Owner

rlanvin commented Apr 27, 2019

Good catch. Do you want to create a pull request?

@madeincosmos
Copy link
Contributor Author

Sure, there it is 🙂

@bor0
Copy link

bor0 commented May 30, 2019

@madeincosmos thanks for working on this!

@rlanvin our project depends on this fix, is there a new release planned anytime soon?

@rlanvin
Copy link
Owner

rlanvin commented May 30, 2019

@bor0 Sure, I just released version 2.1.0 now.

@bor0
Copy link

bor0 commented May 30, 2019

@rlanvin thank you! Kudos for the fast response :)

@SergkeiM
Copy link

SergkeiM commented Apr 7, 2021

Hi @madeincosmos @rlanvin

Have same issue with:

The locale option does not look like a valid locale: C.UTF-8. For more option install the intl extension.

In order to fix this is mandatory to install intl?

@rlanvin
Copy link
Owner

rlanvin commented Apr 8, 2021

In order to fix this is mandatory to install intl?

Hi @FROXZ, no it's not - I believe the reason you're seeing this error is that "C" as a locale is simply not supported (since it doesn't correspond to any language file).

@SergkeiM
Copy link

SergkeiM commented Apr 8, 2021

Hi @rlanvin thank you for reply.

Seems this works without chaning php/server locale:

$rrule->humanReadable([
	'use_intl' => false,
	'locale' => 'en',
]);

P.S. Thank you for amazing library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants