The apostrophe should be added as an thousands marker in the number module.

Switzerland and Liechtenstein uses the apostrophe as thousand marker:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

weri’s picture

Category: feature » bug

We need this for ongoing projects. That is the reason why i changed the category to bug.

weri’s picture

Status: Active » Needs review

Patch is provided...

Status: Needs review » Needs work

The last submitted patch, number_thousands_marker_apostrophe.patch, failed testing.

oriol_e9g’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
FileSize
549 bytes
529 bytes

Firsts add in D8.
Added a patch for D8 & D7.

tstoeckler’s picture

We usually do "'" instead of '\'', but I'm not sure that warrants a re-roll.

oriol_e9g’s picture

Status: Needs review » Needs work

The last submitted patch, add-apostrophe-1370346-6.patch, failed testing.

oriol_e9g’s picture

Status: Needs work » Needs review
FileSize
548 bytes
528 bytes

Ops! Too fast!

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.
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...

Alan D.’s picture

While 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]

oriol_e9g’s picture

Assigned: Unassigned » oriol_e9g
Status: Reviewed & tested by the community » Needs work

Ok, I'm going to add all the options.

Alan D.’s picture

Supply two patches (or one new one) as the core maintainers may or may not like the extended options :)

oriol_e9g’s picture

My 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:

echo 'Arabic Decimal Separator:' . chr(1644);
echo '<br />';
echo 'Arabic Thousands Separator:' . chr(1643);

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

oriol_e9g’s picture

Ops! All separators patch. Note that the arabic characters are not representing correctly in my local system.

oriol_e9g’s picture

Category: bug » feature
FileSize
585 bytes

Ok. 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?

weri’s picture

The 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.

scito’s picture

Status: Needs review » Reviewed & tested by the community

Apostrophe and thin space make sense. Let's add them.

Dries’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to D7

Committed to 8.x. Moving this to 7.x; we could backport this one.

oriol_e9g’s picture

Version: 8.x-dev » 7.x-dev
Assigned: oriol_e9g » Unassigned
Status: Patch (to be ported) » Needs review
FileSize
565 bytes

Yeah!!! This is the port to D7!

scito’s picture

Status: Needs review » Reviewed & tested by the community

Manually tested. Straight forward. This small patch is OK for D7.

sun’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs work

Um. Was the thin space tested?

+++ b/core/modules/field/modules/number/number.module
@@ -228,6 +228,8 @@ function number_field_formatter_settings_form($field, $instance, $view_mode, $fo
+      chr(8201) => t('Thin space'),

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:

var_dump(chr(8201));      // string(1) "	"
var_dump(ord(chr(8201))); // int(9)
var_dump(chr(9));         // string(1) "	"

And as http://www.asciitable.com nicely clarifies, that's a TAB, not a thin-space. :)

oriol_e9g’s picture

Assigned: Unassigned » oriol_e9g
oriol_e9g’s picture

Status: Needs work » Needs review
FileSize
557 bytes

Ok, first of all remove the thin space option.

oriol_e9g’s picture

Status: Needs review » Reviewed & tested by the community

We are only removing a new option that it's adding a bug, after the commit we can discuss how to add it properly.

sun’s picture

Status: Reviewed & tested by the community » Needs review

I 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.

weri’s picture

The "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.

Alan D.’s picture

And 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

$thinspace = html_entity_decode('&#8201;', ENT_NOQUOTES, 'UTF-8');
$arabic_decimal_sep = html_entity_decode('&#x066B;', ENT_NOQUOTES, 'UTF-8');
$arabic_thousand_sep = html_entity_decode('&#x066C;', ENT_NOQUOTES, 'UTF-8');
oriol_e9g’s picture

Added all separators in #26 and #10, not tested.

oriol_e9g’s picture

And 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.

Alan D.’s picture

@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.

sun’s picture

All 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).

oriol_e9g’s picture

FileSize
80.4 KB

I have tested the patches in #28 and #29 with Apache/2.2.22 (Win32) PHP/5.3.13

The HTML form is correctly created:

html separators

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 :(

oriol_e9g’s picture

FileSize
27.45 KB

When I disabed javascript the save action is performed but the non-ascii characters are not displayed propertly.
error utf-8
Server configuration problem???

scito’s picture

FileSize
18.65 KB

Um. Was the thin space tested?

Yes, 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.

chr(8201)

This is really more complicated than I initially thought.

In between I researched about Unicode.

But the Thin space, Right single quotation mark, Arabic thousands separator and Arabic decimal separator are not working.

I think the reason is the PHP function number_format().

Changelog
5.4.0 This function now supports multiple bytes in dec_point and thousands_sep. Only the first byte of each separator was used in older versions.

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.

swentel’s picture

Component: field system » number.module
azuledu’s picture

Could you apply the finished part of the patch to D7?

Thanks.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll
Nitesh Sethia’s picture

Assigned: oriol_e9g » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll +#drupalgoa2015
FileSize
13.32 KB

Rerolled the patch

tstoeckler’s picture

Status: Needs review » Needs work

Number 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).

jhedstrom’s picture

Issue tags: +Needs reroll

Adding tag back.

ravi.khetri’s picture

Status: Needs work » Needs review
FileSize
13.36 KB

Re-rolled.

Status: Needs review » Needs work

The last submitted patch, 41: add_apostrophe_as-1370346-41.patch, failed testing.

dcam’s picture

Issue tags: -Needs reroll

#41 still applies. Removing the "Needs reroll" tag in preparation for Drupalcon Los Angeles sprints.

Status: Needs work » Needs review
jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The patch in #41 is not against Drupal 8.

David_Rothstein’s picture

(More specifically, it actually is against Drupal 8, but contains the wrong code.)

See #39 for what needs to be done.

rteijeiro’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs work » Patch (to be ported)
Issue tags: -#drupalgoa2015, -Needs reroll

It 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)

therealssj’s picture

Here is a patch for D7.

therealssj’s picture

Status: Patch (to be ported) » Needs review
monnerat’s picture

Still not available in 7.x, but patch #48 is not correct (right parent not properly placed). The fixed attached patch works for me.

  • Dries committed 188083a on 8.3.x
    - Patch #1370346 by oriol_e9g, weri: added apostrophe and thins space as...

  • Dries committed 188083a on 8.3.x
    - Patch #1370346 by oriol_e9g, weri: added apostrophe and thins space as...

  • Dries committed 188083a on 8.4.x
    - Patch #1370346 by oriol_e9g, weri: added apostrophe and thins space as...

  • Dries committed 188083a on 8.4.x
    - Patch #1370346 by oriol_e9g, weri: added apostrophe and thins space as...

  • Dries committed 188083a on 9.1.x
    - Patch #1370346 by oriol_e9g, weri: added apostrophe and thins space as...