CollationFa: Third time's the charm
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 28 Dec 2016 15:10:24 +0000 (16:10 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 5 Jan 2017 14:54:00 +0000 (15:54 +0100)
We have to use a tertiary sortkey for everything with the primary
sortkey of 2627. Otherwise, the "Remove duplicate prefixes" logic
in IcuCollation would remove them.

The following characters will now be considered separate letters in
the 'xx-uca-fa' collation for the purpose of displaying the headings
on category pages: ء ئ ا و ٲ ٳ

Bug: T139110
Change-Id: Ibbea5d76348e4cdc38b74cba44286910b2ed592f

includes/collation/CollationFa.php

index b7e45cc..9cce087 100644 (file)
  */
 
 /**
- * Temporary workaround for incorrect collation of Persian language ('fa') in ICU (bug T139110).
+ * Temporary workaround for incorrect collation of Persian language ('fa') in ICU 52 (bug T139110).
  *
- * 'ا' and 'و' should not be considered the same letter for the purposes of collation in Persian.
+ * All of the following will be considered separate letters for category headings in Persian:
+ *  - Characters 'و' 'ا' (often appear at the beginning of words)
+ *  - Characters 'ٲ' 'ٳ' (may appear at the beginning of words in loanwords)
+ *  - Characters 'ء' 'ئ' (don't appear at the beginning of words, but it's easier to implement)
  *
  * @since 1.29
  */
@@ -34,11 +37,14 @@ class CollationFa extends IcuCollation {
        }
 
        public function getPrimarySortKey( $string ) {
-               $firstLetter = mb_substr( $string, 0, 1 );
-               if ( $firstLetter === 'و' || $firstLetter === 'ا' ) {
+               $primary = parent::getPrimarySortKey( $string );
+               // We have to use a tertiary sortkey for everything with the primary sortkey of 2627.
+               // Otherwise, the "Remove duplicate prefixes" logic in IcuCollation would remove them.
+               // This matches sortkeys for the following characters: ء ئ ا و ٲ ٳ
+               if ( substr( $primary, 0, 2 ) === "\x26\x27" ) {
+                       wfDebug( "Using tertiary sortkey for '$string'\n" );
                        return $this->tertiaryCollator->getSortKey( $string );
                }
-
-               return parent::getPrimarySortKey( $string );
+               return $primary;
        }
 }