retro-go icon indicating copy to clipboard operation
retro-go copied to clipboard

translations: Add Simplified Chinese language support

Open ioiotor opened this issue 4 months ago • 12 comments

Add Simplified Chinese language support

ioiotor avatar Jul 27 '25 01:07 ioiotor

Right now retro-go doesn't have the fonts to cover Chinese so it cannot work...

Do you know what UTF-8 ranges are needed by your translations? I can probably update our fonts with them included.

ducalex avatar Aug 18 '25 01:08 ducalex

I used the font "fusion-pixel-font-12px-monospaced-ttf-v2025.08.11.zip" to generate "FusionPixel12.c" based on "font_converter.py". After compiling the firmware, I tested it on the device and encountered no issues. "translation_zh.txt" contains the Chinese vocabulary used in the Chinese translation, while "translations_zh_unicode_Dec.txt" is the converted Unicode in decimal code. translations_zh_unicode_Dec.txt translation_zh.txt FusionPixel12.c

194

ioiotor avatar Aug 18 '25 13:08 ioiotor

The game file names appear as garbled characters. If all Chinese characters are included, the compiled firmware would be too large. I think we should add the basic Level 1 Chinese character list of commonly used characters, totaling 3,755. mixed_3818_dec.txt mixed_3818.txt 3755.txt FusionPixel12.c 3755.txt is the Chinese National Standard Level 1 character set. mixed_3818.txt is a combined file of the Chinese National Standard Level 1 characters and the characters used in Chinese translations. mixed_3818_dec.txt is the Unicode decimal file after combining the characters. FusionPixel12.c is the converted font file.

ioiotor avatar Aug 18 '25 23:08 ioiotor

Thanks for your work! 92542 added bytes per app is a lot. I'd like to add Chinese support, but we'll have to either:

  • Make Chinese support optional at build time (individual targets could opt into it, plus maybe an option in rg_tool.py)
  • Or find a way to share fonts between apps. A shared data partition maybe.

The game file names appear as garbled characters.

My understanding is that we need to enable dynamic codepage and UTF-8 support in FATFS. However it says that it adds 480KB per app which is a lot...

image

ducalex avatar Aug 19 '25 21:08 ducalex

Only enabling the Dynamic (all code pages supported) option will occupy 480KB, while a single codepage will not take up such a large amount of space. After enabling CONFIG_FATFS_API_ENCODING_UTF_8=y, the codepage—whether cp437 or cp936—will correctly display Chinese characters. After selecting codepage as CP437 and enabling CONFIG_FATFS_API_ENCODING_UTF_8=y, I tested using the word "hello" in various languages as filenames. The squares (□) shown in the image are because the FusionPixel font only includes specific languages. Characters included in the font will display normally. 514c2d8be9c8e02b26125f220cba0eb9

The following shows the scenarios with and without CONFIG_FATFS_API_ENCODING_UTF_8=y enabled.

4849664 Aug 21 08:52 retro-go_1.45-51-g73e79-dirty_rachel-esp32.img


ESP-IDF Partition Table

Name, Type, SubType, Offset, Size, Flags

nvs,data,nvs,0x9000,16K, otadata,data,ota,0xd000,8K, phy_init,data,phy,0xf000,4K, launcher,app,ota_0,0x10000,1088K, retro-core,app,ota_1,0x120000,1M, prboom-go,app,ota_2,0x220000,832K, gwenesis,app,ota_3,0x2f0000,1M, fmsx,app,ota_4,0x3f0000,704K,


4849664 Aug 21 08:49 retro-go_1.45-51-g73e79-dirty_rachel-esp32.img


ESP-IDF Partition Table

Name, Type, SubType, Offset, Size, Flags

nvs,data,nvs,0x9000,16K, otadata,data,ota,0xd000,8K, phy_init,data,phy,0xf000,4K, launcher,app,ota_0,0x10000,1088K, retro-core,app,ota_1,0x120000,1M, prboom-go,app,ota_2,0x220000,832K, gwenesis,app,ota_3,0x2f0000,1M, fmsx,app,ota_4,0x3f0000,704K,


ioiotor avatar Aug 21 '25 01:08 ioiotor

Sorry, I accidentally closed the PR... But I’ve now updated the code to the latest version and changed [RG_LANG_CHS] = "中文" to [RG_LANG_CHS] = "简体中文". Using just "中文" was too vague and might have caused confusion, as someone might want to submit a PR related to Traditional Chinese.

ioiotor avatar Aug 21 '25 02:08 ioiotor

  • Make Chinese support optional at build time (individual targets could opt into it, plus maybe an option in rg_tool.py)

+1

KD-MM2 avatar Aug 22 '25 00:08 KD-MM2

After enabling CONFIG_FATFS_API_ENCODING_UTF_8=y, the codepage—whether cp437 or cp936—will correctly display Chinese characters.

Thanks for testing, I confirm that it works and it doesn't increase binary size so I've added it to all targets. So that's one problem solved.

Because of the translations.h format, it would be a bit difficult to make Chinese support optional there. We'd have to add an #ifdef to each string which is absurd. It's probably simpler to have Chinese strings always be compiled, I haven't checked but I suppose it's not too big increase, 2-3KB/app?

So what needs to be conditional at compile time is only the inclusion of Chinese glyphs in fonts.

ducalex avatar Aug 23 '25 19:08 ducalex

Can you add the font to the PR? Both .c and .ttf in case we ever need to regenerate it.

ducalex avatar Aug 23 '25 23:08 ducalex

The font and the converted font files have been committed.
They include the characters required for Chinese translation and a total of 3950 Chinese characters from the Level 1 set of the Chinese National Standard.

ioiotor avatar Aug 25 '25 01:08 ioiotor

Sorry for the long delay! I've tested the changes and it seems to work fine, though my ability to test is very limited.

The big glyph table certainly slows down text drawing, glyph lookup will need to be optimized eventually, but for now it seems to still be perfectly usable.

I'd like to add flags to selectively enable Chinese support before merging the PR, may I commit to your branch?

I'd likely add a flag that can be defined in the target's config.h to enable Chinese support, and maybe a flag for rg_tool.py like --with-chinese-support to force enable it for any target. Also maybe add code to force the Fusion font when Chinese language is selected in the menu.

ducalex avatar Sep 09 '25 23:09 ducalex

Thank you for taking the time to test. You are welcome to commit to my branch anytime. Additionally, I tested it on the esp32-p4, and the performance is much smoother.

ioiotor avatar Sep 10 '25 00:09 ioiotor