{"id":9757,"library":"fold-to-ascii","title":"Fold-to-ASCII","description":"A Python port of the Apache Lucene ASCII Folding Filter, this library converts alphabetic, numeric, and symbolic Unicode characters outside the Basic Latin block into their ASCII equivalents if they exist. It's currently at version 1.0.2.post1 and is a stable, low-cadence utility library focused on character folding rather than full transliteration.","status":"active","version":"1.0.2.post1","language":"en","source_language":"en","source_url":"https://github.com/spanishdict/fold_to_ascii","tags":["string-processing","unicode","ascii-conversion","text-utility","lucene"],"install":[{"cmd":"pip install fold-to-ascii","lang":"bash","label":"Install fold-to-ascii"}],"dependencies":[],"imports":[{"symbol":"fold","correct":"from fold_to_ascii import fold"}],"quickstart":{"code":"from fold_to_ascii import fold\n\n# Example 1: Characters with direct ASCII equivalents\ntext_with_accents = \"Crème brûlée is delicious!\"\nascii_text = fold(text_with_accents)\nprint(f\"Original: {text_with_accents}\")\nprint(f\"Folded:   {ascii_text}\")\n\n# Example 2: Characters without direct ASCII equivalents\ntext_with_non_folding = \"Hello, 你好 👋 world!\"\nascii_text_non_folding = fold(text_with_non_folding)\nprint(f\"Original: {text_with_non_folding}\")\nprint(f\"Folded:   {ascii_text_non_folding}\")","lang":"python","description":"Demonstrates the core functionality of `fold` for characters with and without direct ASCII equivalents, showing how non-folding characters are replaced with question marks."},"warnings":[{"fix":"Be aware of this substitution behavior. If preserving or explicitly handling non-folding characters is required, pre-process the string (e.g., remove them) or use a different library for broader transliteration needs.","message":"Characters without a direct ASCII equivalent (e.g., CJK characters, emojis, or many symbols) are converted to '?' (question mark) characters by default, as the Lucene folding filter does not define mappings for them.","severity":"gotcha","affected_versions":"all"},{"fix":"Understand the distinction between ASCII folding and transliteration. For more comprehensive transliteration (e.g., '你好' to 'Ni Hao'), consider libraries like `unidecode` which offer broader character set mappings.","message":"This library performs ASCII 'folding', which is a specific type of character mapping. It is not a general-purpose 'transliteration' library that attempts to convert characters into phonetic or semantic equivalents across different languages. It strictly follows the rules of the Apache Lucene ASCII Folding Filter.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Add `from fold_to_ascii import fold` at the top of your script or module.","cause":"The `fold` function was not imported into the current scope.","error":"NameError: name 'fold' is not defined"},{"fix":"Ensure you pass a string to the function, e.g., `fold('your text here')`.","cause":"The `fold` function was called without passing any string argument.","error":"TypeError: fold() takes exactly one argument (0 given)"},{"fix":"Use `from fold_to_ascii import fold` and then call `fold('text')`, or if you prefer `import fold_to_ascii`, call it as `fold_to_ascii.fold('text')`.","cause":"You likely imported the module as `import fold_to_ascii` and then tried to call `fold()` directly, or did `from fold_to_ascii import *` and `fold` wasn't included (unlikely for such a small library).","error":"AttributeError: 'module' object has no attribute 'fold'"}]}