jenssegers / date

🗓 A library to help you work with dates in multiple languages, based on Carbon.
https://jenssegers.com
MIT License
1.81k stars 244 forks source link

Arabic numbers support #346

Closed AbdullahAlhariri closed 1 year ago

AbdullahAlhariri commented 1 year ago

Hello,

I noticed that the repository hasn't been updated in a while. But I was attempting to convert an date to Arabic, and I noticed that the numbers were not converted with the date. Did you forget to convert the numbers as well or was this implemented specifically as is?

Current output image but should be: image

kylekatarnls commented 1 year ago

Hello,

I can't tel for your case as you don't provide the code to run to reproduce your issue.

But Carbon supports alternative numbers via ->isoFormat() in some languages (the languages where volunteer translators contributed to add them).

CarbonImmutable::parse('2023-01-28')
  ->locale('az_IR')
  ->isoFormat('dddd MMMM OD')
شنبه ژانویه ۲۸

https://play.phpsandbox.io/nesbot/carbon?version=2.65.0.0&input=%3C%3Fphp%0A%0ACarbonImmutable%3A%3Aparse(%272023-01-28%27)%0A%20%20-%3Elocale(%27az_IR%27)%0A%20%20-%3EisoFormat(%27dddd%20MMMM%20OD%27)%3B

If the locale you want should have it, but they are not in Carbon, you may propose a pull-request to add the missing alt_numbers following this example: https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Lang/az_IR.php#L26

AbdullahAlhariri commented 1 year ago

Thank you for your response.

It appears that az_IR is the Persian locale, which is written in Arabic script, but it's not arabic. The isoFormat function does not seem to have an effect when the locale is set to ar_SA (Saudi Arabia). It is likely that this behavior has been implemented intentionally.

kylekatarnls commented 1 year ago

There is no "intention" there. As said, isoFormat will use alt_numbers if someone provided the translations for it in the given language and no one contributed yet for this feature in ar and ar_SA, it's open-source, PRs are welcome, if you're fluent in Arabic add it there:

https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Lang/ar.php https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Lang/ar_SA.php

Provide some source/reference so it can compared.

AbdullahAlhariri commented 1 year ago

sure, I'll contribute to it.

AbdullahAlhariri commented 1 year ago

@kylekatarnls I have created a PR for this issue. see here

kylekatarnls commented 1 year ago

Thanks 🙏