Skip to content

Add support for hebrew translation#8344

Open
BLooperZ wants to merge 3 commits intodiasurgical:masterfrom
BLooperZ:hebrew_support3
Open

Add support for hebrew translation#8344
BLooperZ wants to merge 3 commits intodiasurgical:masterfrom
BLooperZ:hebrew_support3

Conversation

@BLooperZ
Copy link
Copy Markdown
Contributor

@BLooperZ BLooperZ commented Dec 10, 2025

Another attempt at supporting hebrew translation following #7512
This attempt is based on the new BiDi library (SheenBiDi) added by @glebm (Thanks!)

Few notes:

  • I haven't found documentation and example of using SheenBiDi, but the AI generated code in unicode-bidi.cpp seems to work well
  • The most prominent change (and enabler) is having the text drawn line by line, it seems to work correctly but I would like more eyes on it, should be tested to not affect english, mostly cursor and highlights
  • The hebrew translation itself is only the main menu at the moment, I can exclude it until translation is complete if you so wish
  • I should open another PR to devilutionx-assets with the fonts
  • BiDi behaviour for the cursor and highlights are not yet implemented, I did came up with a neat trick to support BiDI cursor while experimenting few years ago for another project, hope the same method will fit here as well, need to research more regarding highlights, but we should make sure they still work with LTR language before even starting.

Thank you

@BLooperZ BLooperZ mentioned this pull request Dec 10, 2025
constexpr char32_t ZWSP = U'\u200B'; // Zero-width space

// Convert logical text order to visual text order using SheenBidi
std::string ConvertLogicalToVisual(std::string_view input)
Copy link
Copy Markdown
Collaborator

@glebm glebm Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the AI-generated code here went for a rather complicated solution.

Instead, the rendering can be done directly without any text copying or extra work, which is a very nice feature of SheenBidi.

You can do this by iterating over the "runs" (SBParagraphCreateLine, SBLineGetRunsPtr, SBLineGetRunCount).

Within a run, all characters have the same direction, which can be determined by looking at whether the run_level field of the run is even. Then, for reverse runs, you can use SBCodepointDecodePreviousFromUTF8 to get the code point in the reverse direction.

You can look at other projects using SheenBidi (many mentioned in SB's readme here https://github.com/Tehreer/SheenBidi) for inspiration but please be careful with the license if copy-pasting code from other projects.

SheenBidi lacks documentation but it implements the Unicode Bidirectional Algorithm precisely and uses the same names for things as in the algorithm description, so reading this document should give you a pretty good idea of how to use SB: https://unicode.org/reports/tr9/

@glebm
Copy link
Copy Markdown
Collaborator

glebm commented Dec 12, 2025

It'd be nice to also add tests to text_render_integration_test (including a test with highlighting).

For creating the Hebrew fonts, if we don't already have them, I have a basic font converter here https://github.com/diasurgical/devilutionx-font-converter, with an example of how to use it here diasurgical/devilutionx-assets#18

@AJenbo
Copy link
Copy Markdown
Member

AJenbo commented Dec 12, 2025

We currently only have hebrew (font page 0x05) in the small font used on error messages and the credit screen. the upside is that we don't have a renderer script for that so it does allow use to pretty easily create a fonteset for Hebrew.

Thaana and N’Ko should also work once we get this PR merged (font page 0x07) .

For other RTL scripts we would also need support for shaping in the renderer so probably it would be to early to worry about generating the font pages (0x06, 0x07, 0x08) for them.

@BLooperZ
Copy link
Copy Markdown
Contributor Author

@AJenbo Great, I drew hebrew fonts back then but I just the larger ones (missing only the 2 smallest sizes)

@AJenbo
Copy link
Copy Markdown
Member

AJenbo commented Dec 13, 2025

Fun fact, emojis also require shaping, and Google kind of require this feature for chat applications.

@glebm
Copy link
Copy Markdown
Collaborator

glebm commented Dec 14, 2025

The good news is that the converter from diasurgical/devilutionx-assets#18 works pretty well for large font sizes. It doesn't work that well for small font sizes yet.

@BLooperZ
Copy link
Copy Markdown
Contributor Author

I opened PR for the fonts: diasurgical/devilutionx-assets#21

@AJenbo
Copy link
Copy Markdown
Member

AJenbo commented Dec 16, 2025

@AJenbo
Copy link
Copy Markdown
Member

AJenbo commented Dec 16, 2025

I added the Hebrew font so if you update your PR it should now render correctly ingame.

@BLooperZ BLooperZ mentioned this pull request Dec 26, 2025
@BLooperZ BLooperZ force-pushed the hebrew_support3 branch 2 times, most recently from e0089d9 to e9b8059 Compare January 14, 2026 16:54
@strich
Copy link
Copy Markdown
Collaborator

strich commented Jan 29, 2026

Hey @BLooperZ, just checking in on the status of this PR. Are you still planning to get it in? I'd love to see this move forward!

@BLooperZ
Copy link
Copy Markdown
Contributor Author

yes, trying to figure out cursor behaviour with BiDi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants