Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The apostrophe should be added as an thousands marker in the number module.
Switzerland and Liechtenstein uses the apostrophe as thousand marker:
Comment | File | Size | Author |
---|---|---|---|
#50 | 001-more-number-separators-1370346.patch | 1.33 KB | monnerat |
#48 | 1370346-48.patch | 1.32 KB | therealssj |
#41 | add_apostrophe_as-1370346-41.patch | 13.36 KB | ravi.khetri |
#38 | add_apostrophe_as-1370346-38.patch | 13.32 KB | Nitesh Sethia |
#29 | number-separators-1370346-29.patch | 1.39 KB | oriol_e9g |
Comments
Comment #1
weri CreditAttribution: weri commentedWe need this for ongoing projects. That is the reason why i changed the category to bug.
Comment #2
weri CreditAttribution: weri commentedPatch is provided...
Comment #4
oriol_e9gFirsts add in D8.
Added a patch for D8 & D7.
Comment #5
tstoecklerWe usually do "'" instead of '\'', but I'm not sure that warrants a re-roll.
Comment #6
oriol_e9gYeah!
Comment #8
oriol_e9gOps! Too fast!
Comment #9
tstoecklerThanks.
RTBC if it comes back green.
I didn't know that the Swiss do this, but I checked. For reference, this is a page on the website on of the biggest Swiss newspapers: http://www.nzz.ch/finanzen/indizes/_detail?ID_NOTATION=1555183&ID_INSTRU...
Comment #10
Alan D. CreditAttribution: Alan D. commentedWhile looking at this, should the Arabic separators be added too?
U+066B ٫ Arabic Decimal Separator
U+066C ٬ Arabic Thousands Separator
And there is also the thin space recommended by many agencies:
U+2009 thin space (HTML:    ).
IE: 123 456 789 [space] and 123 456 789 [thin space]
Comment #11
oriol_e9gOk, I'm going to add all the options.
Comment #12
Alan D. CreditAttribution: Alan D. commentedSupply two patches (or one new one) as the core maintainers may or may not like the extended options :)
Comment #13
oriol_e9gMy system it's working fine with the Thin space but I have problems writing the arabic characters. For example, if I use chr() to print these characters:
In my system it appear as:
Arabic Decimal Separator:l
Arabic Thousands Separator:k
"l" and "k"! WTF! O.o
Any idea of how to represent correctly the arabic characters? Maybe a problem with my system configuration?
Added 3 patches: Only apostrophe addition, apostrophe + thin space addition, apostrophe + thin space + arabic separators addition
Comment #14
oriol_e9gOps! All separators patch. Note that the arabic characters are not representing correctly in my local system.
Comment #15
oriol_e9gOk. We have some representation problems with Arabic separators, so move forward and put the two new thousand separators (apostrophe for Swiss and thin space as recommend some agencies). RTBC?
Comment #16
weri CreditAttribution: weri commentedThe patch #15 works. It would be great to see the patch new-numeric-reparators-1370346-15.patch applied for D8 and as backport for the next D7 release. Otherwise I have always to "hack" the core.
Comment #17
scitoApostrophe and thin space make sense. Let's add them.
Comment #18
Dries CreditAttribution: Dries commentedCommitted to 8.x. Moving this to 7.x; we could backport this one.
Comment #19
oriol_e9gYeah!!! This is the port to D7!
Comment #20
scitoManually tested. Straight forward. This small patch is OK for D7.
Comment #21
sunUm. Was the thin space tested?
http://php.net/manual/en/function.chr.php clearly documents the argument as
$ascii
. The maximum value is 255.This user comment explains the behavior of chr() for values > 255 and < 255:
http://php.net/manual/en/function.chr.php#91868
And this is also what happens:
And as http://www.asciitable.com nicely clarifies, that's a TAB, not a thin-space. :)
Comment #22
oriol_e9gComment #23
oriol_e9gOk, first of all remove the thin space option.
Comment #24
oriol_e9gWe are only removing a new option that it's adding a bug, after the commit we can discuss how to add it properly.
Comment #25
sunI think it would make more sense to simply replace the chr() with the appropriate Unicode character.
That said, I also wonder whether the apostrophe character is the "real" typographic apostrophe that is used as thousand separator. I almost guess that there is a dedicated Unicode character for that, too.
Comment #26
weri CreditAttribution: weri commentedThe "normal" typographic apostrophe ’ is correct (Unicode U+2019). Often the replacement ' is used on webpages instead (Unicode U+0027).
Maybe it is possible to ad both? When we display Financial information from external resources, I have seen both types of apostrophe. And then it's important to choose the same character.
Comment #27
Alan D. CreditAttribution: Alan D. commentedAnd that explains why the Arabic characters were failing.
Maybe html_entity_decode() rather than using the multibyte string library? (if we want to support these) Note that the encoding parameter (the 3rd) is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0
Comment #28
oriol_e9gAdded all separators in #26 and #10, not tested.
Comment #29
oriol_e9gAnd this is the option using html_entity_decode instead of the unicode character. Maybe we can test both #28 and #29 with PHP 5.4 and PHP < 5.4, and add code comments if it's needed.
Comment #30
Alan D. CreditAttribution: Alan D. commented@sun do you know of any issues directly including the characters? These files should be encoded in UTF-8, but if someone saves these in another format, then there may be issues. It seems cleaner than decoding..., although the thin space doesn't show in my editors font, making space and thin space look identical in the UI.
Comment #31
sunAll files in Drupal are in UTF-8. We use the Unicode characters directly everywhere. So #29 is the way to go.
There is some risk in that a developer might use an editor or IDE that doesn't handle UTF-8 correctly, but the only way I could think of to protect ourselves against that would be a unit test for number_field_formatter_settings_form(), which mocks the function parameters and just ensures that the different options have the correct values.
At this point, that feels a bit paranoid to me, so I'd rather leave that test to the hypothetical bug report of the future that fixes the characters because someone screwed them up (if any).
Comment #32
oriol_e9gI have tested the patches in #28 and #29 with Apache/2.2.22 (Win32) PHP/5.3.13
The HTML form is correctly created:
But the Thin space, Right single quotation mark, Arabic thousands separator and Arabic decimal separator are not working.
No errors in the screen or in the log but when I select one of this values and save, the action is not performed and the value is not saved. When I select apostrophe, space, comma... the action is performed, the value saved and correctly displayed in the field example :(
Comment #33
oriol_e9gWhen I disabed javascript the save action is performed but the non-ascii characters are not displayed propertly.
Server configuration problem???
Comment #34
scitoYes, I tested it visually. I saw a space. Actually, the chr(8201) was transformed into char(9), a tab. That explains visual and misleading space. I did not inspect the byte values. So, a little bit too confident.
This is really more complicated than I initially thought.
In between I researched about Unicode.
I think the reason is the PHP function
number_format()
.All these characters are Unicode, thus multi-byte. If only the first byte is taken, then we get an illegal UTF-8 string.
Thus, Thin space, Right single quotation mark, Arabic thousands separator and Arabic decimal separator do not work with PHP 5.3. PHP 5.4 is required for them.
For PHP 5.3, we have to stick we the plain apostrophe. Actually, the initial request.
Comment #35
swentel CreditAttribution: swentel commentedComment #36
azuledu CreditAttribution: azuledu commentedCould you apply the finished part of the patch to D7?
Thanks.
Comment #37
jhedstromComment #38
Nitesh Sethia CreditAttribution: Nitesh Sethia commentedRerolled the patch
Comment #39
tstoecklerNumber module was removed, so this patch will not work.
The relevant code is now in
\Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericFormatterBase::settingsForm()
(for the thousand separator) and in\Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter::settingsForm()
(for the decimal separator).Comment #40
jhedstromAdding tag back.
Comment #41
ravi.khetri CreditAttribution: ravi.khetri commentedRe-rolled.
Comment #43
dcam CreditAttribution: dcam commented#41 still applies. Removing the "Needs reroll" tag in preparation for Drupalcon Los Angeles sprints.
Comment #45
jhedstromThe patch in #41 is not against Drupal 8.
Comment #46
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commented(More specifically, it actually is against Drupal 8, but contains the wrong code.)
See #39 for what needs to be done.
Comment #47
rteijeiro CreditAttribution: rteijeiro at Tieto commentedIt seems it has been fixed in 8.0.x so it just needs backport. Changing version to 7.x-dev (not sure if that's correct)
Comment #48
therealssj CreditAttribution: therealssj commentedHere is a patch for D7.
Comment #49
therealssj CreditAttribution: therealssj commentedComment #50
monnerat CreditAttribution: monnerat commentedStill not available in 7.x, but patch #48 is not correct (right parent not properly placed). The fixed attached patch works for me.