[13.x] Add locale parameter to Number::fileSize(), forHumans(), and abbreviate()#59737
Closed
sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
Closed
[13.x] Add locale parameter to Number::fileSize(), forHumans(), and abbreviate()#59737sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
Conversation
…bbreviate() Co-Authored-By: Sumaiya Zaman <saktar50.cse@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Number::fileSize(),Number::forHumans(), andNumber::abbreviate()now accept an optional?string $locale = nullparameterNumber::format()andNumber::parseFloat()calls insidesummarize()format,percentage,currency,spell,ordinal,spellOrdinal,parse,parseInt,parseFloat) already supported this parameter — this closes the inconsistencyContext
localeparam beforelocaleparam afterNumber::format()Number::percentage()Number::currency()Number::spell()Number::ordinal()Number::fileSize()Number::forHumans()Number::abbreviate()Solution
Added
?string $locale = nullas the last parameter tofileSize(),abbreviate(),forHumans(), and the internalsummarize()method. The locale is forwarded to everystatic::format()andstatic::parseFloat()call within those methods.Example
Before:
After:
Why no breaking changes
All three parameters are appended at the end with a default of
null, preserving full backwards compatibility. Existing calls are unaffected.Changes
src/Illuminate/Support/Number.php— added?string $locale = nulltofileSize(),abbreviate(),forHumans(), andsummarize()tests/Support/SupportNumberTest.php— added locale assertions totestBytesToHumanandtestSummarizeTest Plan
php83 vendor/bin/phpunit tests/Support/SupportNumberTest.php— all 22 tests pass