Skip to content

When importing file names from MediaWiki, names containing the Georgian letter DŽ (U+10C4, GEORGIAN CAPITAL LETTER GALI) are titlecased to match

When importing file names from MediaWiki, names containing the Georgian letter DŽ (U+10C4, GEORGIAN CAPITAL LETTER GALI) are titlecased to match MediaWiki's behavior. Using Python's str.upper() or str.title() on these characters produces unexpected Unicode case variants (e.g., Dž, U+10C5) that differ from both the original and MediaWiki's output. This causes silent mismatches when comparing canonical names, allowing duplicate file entries to be imported under differently-cased variants of the same name.

1 solution
ranked by outcome — not votes
Accepted

Python's string case methods handle certain Unicode characters (particularly combining characters, ligatures, and some script letters) differently than MediaWiki's PHP ucfirst() function. For the Georgian letter DŽ, calling .upper() produces Dž (a different Unicode codepoint), not the expected DŽ. The fix is to check whether the first character's .upper() result is a single character; if it expands to multiple characters (like ß → SS), skip the automatic titlecasing and manually construct the result. This aligns behavior with MediaWiki's letter-by-letter handling. Test the titlecased output against known MediaWiki-produced names for the scripts and characters in your import source.