Skip to content

translate: split multi-word Persian names by character so the output compiles - #3683

Merged
BaseMax merged 3 commits into
mainfrom
fix/translate-names
Nov 19, 2026
Merged

BaseMax merged 3 commits into
mainfrom
fix/translate-names

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

salam translate en wrote a multi-word Persian name differently where it is declared and where it is called, so its own output did not compile.

  • TranslateIdentifierFaToEn and translit_fa_to_en walked the name one byte at a time. The ZWNJ is three bytes, so it never matched the separator test, and every comparison with a Persian letter failed, so nothing was ever transliterated. تابع شمار رقم‌ها with a call شمار رقم ها(...) came out as count_رقم‌ها and count_رقم_ها (E234 and E012). Both functions now walk characters (CharCount and CharAtIndex) and both sites give count_rghm_ha.
  • New test tests/fa/translate/multiword_zwnj_call: a ZWNJ at the declaration and a space at the call, translated to English, built and run.
  • tests/en/check/fix/bidi_after_backslash.fixed still had lowercase .len() after the PascalCase rename.

Checked on a build of this branch: the translated blog example from post 03 now checks clean, match 21 of 21 and types 33 of 33, lib and new pass, and check is 30 of 32.

Not fixed, and not caused by this change:

  • check/{en,fa}/prelude_name fail on a compiler without LLVM. std/thread imports collections since Fix release seed selection and thread imports #3414, so the guard that lets a user file named collections.salam through no longer applies on the C path, and on that path the two modules really do collide in the generated C. The release build takes the LLVM path, where the check never runs. I tried making check accept it and dropped that, because check would then disagree with build, which is what salam check: fail when errors are printed, match what build reports #2685 exists to prevent.
  • translate is 12 of 34 here. The failures are several separate problems in the translator: it does not map comparison operators to the Persian words (and back), some translated names collide with reserved words, a few stored page outputs are stale, and one test hits an unused variable. That needs its own change.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Unicode characters during Persian-to-English transliteration and identifier parsing, while preserving existing separator behavior.
  • Tests
    • Expanded coverage for Persian multiword identifiers and string length handling.

TranslateIdentifierFaToEn and the transliteration table walked the name one byte at a time, so the three byte ZWNJ never matched and no Persian letter was ever transliterated. A name with a ZWNJ at its declaration and a space at the call came out as two different names, count_رقم‌ها and count_رقم_ها, and the translated file did not compile. Both sites now give the same Latin name.
@BaseMax
BaseMax requested a review from a team as a code owner November 19, 2026 17:45
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The transliteration and identifier-splitting loops now scan Unicode characters. Test changes add a Persian digit-count example and update string-length calls in a fixed fixture.

Changes: Unicode Identifier Translation

Layer / File(s) Summary
Unicode character scanning
compiler/name_translate.salam
translit_fa_to_en and TranslateIdentifierFaToEn now scan Unicode characters. Existing separator handling remains unchanged.
Translation test coverage
tests/fa/translate/multiword_zwnj_call.salam, tests/en/check/fix/bidi_after_backslash.fixed
The Persian test adds a function that counts repeated divisions by 10 and prints the result for 2026. The fixed fixture changes four string-length calls from len() to Len().

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: bdadmehr0, erfangnu

Merge Risk: Moderate · up to 391e5

This change makes Persian identifiers transliterate correctly at declaration and call sites. However, different Persian names that share a transliteration can now translate to the same English name, which can cause duplicate declarations or wrong bindings in translated output. Consider adding caller-side disambiguation before merging, or explicitly accept this limitation.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BaseMax
BaseMax merged commit 8161d9d into main Nov 19, 2026
12 of 13 checks passed
@BaseMax
BaseMax deleted the fix/translate-names branch November 19, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant