How to display text in Hindi - हिन्दी

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Eliont
Regular
Posts: 98
Joined: Thu Aug 06, 2009 6:51 am
Completed: Begin of Evangelion, SAO - Smile of the black cat, SAO - Project "Ceramic Heart", Time for Dragons
Location: Russia
Contact:

How to display text in Hindi - हिन्दी

#1 Post by Eliont » Fri Jul 03, 2020 8:09 am

Hello and good time of day.

How ?
Tried 11 different fonts and not a single works - just squares.

User avatar
PyTom
Ren'Py Creator
Posts: 15476
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to display text in Hindi - हिन्दी

#2 Post by PyTom » Fri Jul 03, 2020 5:51 pm

I'm not sure that Ren'Py can display Hindi properly. I think it requires a level of text shaping that Ren'Py doesn't support. That being said, if you're just getting squares, you're not using a font that supports the character set.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3000
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: How to display text in Hindi - हिन्दी

#3 Post by Imperf3kt » Fri Jul 03, 2020 7:16 pm

You may have to turn your text into images, and display those images instead of text.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

User avatar
aswang
Newbie
Posts: 2
Joined: Tue Jul 07, 2020 9:02 pm
Contact:

Re: How to display text in Hindi - हिन्दी

#4 Post by aswang » Sat Jul 11, 2020 11:06 am

If you're making your whole game in Hindi, you just need to change the font to a Devanagari one and make sure that the font file (ex. font.ttf) is copied in your game directory folder, or else renpy won't be able to find it and you'll just get squares (even if the font works elsewhere on your computer).

If you're using multiple languages (ex. Hindi and English) simultaneously, you'll still need to have the fonts in your game folder but you can get Hindi to appear in one of two ways:

1) If it's only on a few occasions, tagging the font every time you have text in Hindi using the font tag or creating a custom tag as a shorthand that will write this out for you:

Code: Select all

init python:

    def hindi_tag(tag, argument, contents):

        font = "NotoSansDevanagariUI-Regular.ttf"

        return [
                (renpy.TEXT_TAG, u"font={}".format(font)),
            ] + contents + [
                (renpy.TEXT_TAG, u"/font"),
            ]

    config.custom_text_tags["hindi"] = hindi_tag
which you can use in your script like this:

Code: Select all

{hindi}your text{/hindi}
2) If it's throughout your game, using front groups and specifying the font and unicode range for Hindi and adding this code into the style specifications for default like this:

Code: Select all

style default:
   #### make sure to remove 
   #properties gui.text_properties()
   #### in order for this to work
    font FontGroup().add("DejaVuSans.ttf", 0x0020, 0x007f).add("DejaVuSans.ttf", 0x200B, 0x200B).add("NotoSansDevanagariUI-Regular.ttf",0x0900, 0x097F)
This automatically applies the font to all Devanagari characters within the specified range (0x0900 to 0x097F), so you don't have to use font tags to get them to show up.

Unfortunately, if you were planning to port to mobile and wanted to let your players provide text input in Hindi, the keyboard will revert to QWERTY on phones. Input works fine though on desktop, and you can try and make a soft keyboard for Hindi input for mobile if needed.

Hope this helps!

User avatar
PyTom
Ren'Py Creator
Posts: 15476
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to display text in Hindi - हिन्दी

#5 Post by PyTom » Sat Jul 11, 2020 2:07 pm

@aswang, does this actuallyt work? I know that there are some issues with text shaping when it comes to Indic languages, but I don't know which languages those issues apply to.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
aswang
Newbie
Posts: 2
Joined: Tue Jul 07, 2020 9:02 pm
Contact:

Re: How to display text in Hindi - हिन्दी

#6 Post by aswang » Sat Jul 11, 2020 3:52 pm

PyTom wrote:
Sat Jul 11, 2020 2:07 pm
@aswang, does this actuallyt work? I know that there are some issues with text shaping when it comes to Indic languages, but I don't know which languages those issues apply to.
Checking again... it does, to an extent. I didn't use the best example when testing this with Devanagari the first time it seems, so I missed some issues, but I do have an interim fix for that for OP now as well.

As for the squares, as you said it mostly seems to be an issue with the unicode scope of the in-built font and whether or not the replacement font is available. I've been playing around with another abugida script in renpy this past week (similar to Devanagari, but also a little less complex in the handling of clusters and diacritics) and the solution I posted has worked for me on both desktop and android (again aside from mobile keyboard reverting to QWERTY). But doing another test with Devanagari now, it works alright, aside from consonant clusters and some diacritics not combining the way they should in Hindi (see how the first vowel is off and the n-d (न् and द्) is different in my screenshots vs the title of this thread). The consonant clusters are still readable, the first vowel isn't (it's basically saying there should be an "i" after the "n", but the virama on the "n" is also saying that there should be no vowel after it).

Here's default renpy vs with fontgroup, vs setting my whole game's font to a Devanagari one:

"Hindi"
example.png
"Devanagari"
devanagari.png
devanagari.png (4.51 KiB) Viewed 207 times
So looking closer, the main trouble renpy is having with Devanagari aside from special ligatures not combining and staying as-is is with the positioning of its vowel diacritics, namely the fact that some go before the consonant, some go after, others above or below, and it can manage all of them except for the ones that go before but are typed in after the consonant. So in "Hindi", it's giving the "i" to the N, and not the H as it should, because the symbol for "i" is typed in after the H, not before it.

And I can test this theory now by typing in the "i" before the H instead... and now it appears properly on screen! This also works if there's a consonant or consonant-vowel pair before it as well. Unfortunately there's still the issue of ligatures and as for vowels this is gonna be annoying for anyone having to type this all out / make changes to script, but it's something.

some kind of fix.png
some kind of fix.png (9.39 KiB) Viewed 207 times

edit: I found a couple Hindi fonts that bypass these issues as they are typed out in roman script and don't use ligatures, so they should work in renpy without issue, but may be more difficult to work with if you're not writing in a word processor/coding program with custom keymapping/shortcuts/easy symbol input since not all of the characters are mapped to keys and they dont automatically combine for things like clusters, and have the same issue with diacritics appearing before needing to be written in before the consonant.

Post Reply

Who is online

Users browsing this forum: No registered users