Skip to content

Conversation

@farad-tech
Copy link

Many Laravel developers working with Persian or Arabic inputs often need to normalize user-entered numeric values (for example, phone numbers or amounts) before validation or database storage. Having this as a built-in helper improves developer experience and prevents code duplication across projects.

All tests are included and passing.

Comment on lines +529 to +533
* Converting Persian/Arabic digits to English
* @param mixed $value
* @return string
*/
function to_english_numbers($value): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would I know that this is specific to Persian/Arabic digits from the helper name alone? And these are not English, the are Arabic numbers, just not Eastern Arabic numerals, but Western Arabic numerals.

And what about other numbering systems?

Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
if (! function_exists('to_english_numbers')) {
/**
* Converting Persian/Arabic digits to English
* @param mixed $value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really mixed? Shouldn't this be

Suggested change
* @param mixed $value
* @param string $value

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this function to Number helper so we don't need to repeat it here. I'll remove that from helper.php

/**
* Converting Persian/Arabic digits to English
* @param mixed $value
* @return string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After using Number::toEnglishFormat() (#57669 (comment)), the return type has to be adjusted as well:

Suggested change
* @return string
* @return int|float

/**
* Converting Persian/Arabic digits to English
* @param mixed $value
* @return bool|float|int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bool?

Comment on lines 8 to 9
use Illuminate\Support\Fluent;
use Illuminate\Support\HigherOrderTapProxy;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and you have to import the Number class 😉 (#57669 (comment))

https://github.com/laravel/framework/actions/runs/19084359967/job/54521096356?pr=57669

Suggested change
use Illuminate\Support\Fluent;
use Illuminate\Support\Number;
use Illuminate\Support\HigherOrderTapProxy;

@farad-tech farad-tech closed this Nov 5, 2025
Comment on lines +450 to +451
$numberFormatter = new NumberFormatter('ar-u-nu-latn', NumberFormatter::DECIMAL);
return $numberFormatter->parse($value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could even use internal methods:

Suggested change
$numberFormatter = new NumberFormatter('ar-u-nu-latn', NumberFormatter::DECIMAL);
return $numberFormatter->parse($value);
return self::parse($value, locale: 'ar-u-nu-latn');

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 this pull request may close these issues.

2 participants