Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Fixed PercentToLocalizedStringTransformer to accept both comma and dot as decimal separator, if possible#22586

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
aaa2000 wants to merge2 commits intosymfony:2.7fromaaa2000:percent-comma-dot

Conversation

@aaa2000
Copy link
Contributor

@aaa2000aaa2000 commentedApr 30, 2017
edited by nicolas-grekas
Loading

QA
Branch?2.7
Bug fix?yes-ish
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT

Implements the same behaviour thatNumberToLocalizedStringTransformer in order to accept both comma and dot implemented in#5941

}

$formatter =$this->getNumberFormatter();
$groupSep =$formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
Copy link
ContributorAuthor

@aaa2000aaa2000Apr 30, 2017
edited
Loading

Choose a reason for hiding this comment

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

I duplicate code ofNumberToLocalizedStringTransformer.php maybe it is better to use it directly ?

-        if (!is_string($value)) {-            throw new TransformationFailedException('Expected a string.');-        }-         if ('' === $value) {             return;         }          $formatter = $this->getNumberFormatter();-        $groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);-        $decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);         $grouping = $formatter->getAttribute(\NumberFormatter::GROUPING_USED);--        if ('.' !== $decSep && (!$grouping || '.' !== $groupSep)) {-            $value = str_replace('.', $decSep, $value);-        }--        if (',' !== $decSep && (!$grouping || ',' !== $groupSep)) {-            $value = str_replace(',', $decSep, $value);-        }--        // replace normal spaces so that the formatter can read them-        $value = $formatter->parse(str_replace(' ', ' ', $value));--        if (intl_is_failure($formatter->getErrorCode())) {-            throw new TransformationFailedException($formatter->getErrorMessage());-        }+        $transformer = new NumberToLocalizedStringTransformer($this->scale, (bool) $grouping);+        $value = $transformer->reverseTransform($value);

@nicolas-grekasnicolas-grekas changed the title[Form] Fixed PercentToLocalizedStringTransformer to accept both comma…[Form] Fixed PercentToLocalizedStringTransformer to accept both comma and dot as decimal separator, if possibleMay 2, 2017
@nicolas-grekasnicolas-grekas added this to the2.7 milestoneMay 2, 2017
$decSep =$formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
$grouping =$formatter->getAttribute(\NumberFormatter::GROUPING_USED);

if ('.' !==$decSep && (!$grouping ||'.' !==$groupSep)) {
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be easier to first remove the grouping character and then replace$decSep with a dot?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I prefer to use the same logic asNumberToLocalizedStringTransformer but if you want, I can try

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM
@xabbuh would you be +1 even if we ignore your comment?

* "choice_value"
* "choice_attr"
* "group_by"
* added PercentToLocalizedStringTransformer to accept both comma and dot as decimal separator, if possible

Choose a reason for hiding this comment

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

I think we don't need this change, we don't put entries there for bug fixes


publicfunctiontestDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot()
{
\Locale::setDefault('fr');

Choose a reason for hiding this comment

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

tests are failing because this method is not always available, can you fix it@aaa2000 ?

@aaa2000
Copy link
ContributorAuthor

Tests fixed and revert the change in changelog.

@fabpot
Copy link
Member

@xabbuh@nicolas-grekas Any decision on this one?

@fabpot
Copy link
Member

Thank you@aaa2000.

@fabpotfabpot closed thisOct 1, 2017
fabpot added a commit that referenced this pull requestOct 1, 2017
… both comma and dot as decimal separator, if possible (aaa2000)This PR was squashed before being merged into the 2.7 branch (closes#22586).Discussion----------[Form] Fixed PercentToLocalizedStringTransformer to accept both comma and dot as decimal separator, if possible| Q             | A| ------------- | ---| Branch?       | 2.7 <!-- see comment below -->| Bug fix?      | yes-ish| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->| BC breaks?    | no| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->| Tests pass?   | yes| Fixed tickets | <!-- #-prefixed issue number(s), if any -->| License       | MIT<!--- Bug fixes must be submitted against the lowest branch where they apply  (lowest branches are regularly merged to upper ones so they get the fixes too).- Features and deprecations must be submitted against the master branch.- Please fill in this template according to the PR you're about to submit.- Replace this comment by a description of what your PR is solving.-->Implements the same behaviour that `NumberToLocalizedStringTransformer` in order to accept both comma and dot implemented in#5941Commits-------f96a7f8 [Form] Fixed PercentToLocalizedStringTransformer to accept both comma and dot as decimal separator, if possible
This was referencedOct 5, 2017
fabpot added a commit that referenced this pull requestOct 10, 2017
This PR was merged into the 2.7 branch.Discussion----------[Form] fix parsing invalid floating point numbers| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#19854,#22586| License       | MIT| Doc PR        |Should make AppVeyor builds pass again. Code borrowed from `NumberToLocalizedStringTransformer`.Commits-------042eac4 [Form] fix parsing invalid floating point numbers
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@xabbuhxabbuhxabbuh left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

5 participants

@aaa2000@fabpot@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp