How to change fonts and texts (Unicode problem)

Moderator: Pocus

Post Reply
oooFUNooo
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 4
Joined: Sun Jun 23, 2019 8:33 am

How to change fonts and texts (Unicode problem)

Post by oooFUNooo » Fri Jul 19, 2019 6:52 am

I'm trying to display Unicode characters, but I have some troubles. Someone, please help me.

I have found following related files.
Font entities: Core/*.ttf
Text entities: Data/Text/*.txt

I could change fonts and texts. However Unicode characters after U+051D weren't displayed.
Is there a hard-coded restriction, or something I can do?

I read this article which says "you may need to use applicable fonts to allow the display of non-ASCII characters".

This is an example where Japanese characters are mapping to before U+051D.
Image

I deleted original post from the main forum and posted new one here.

AndrewGardner
Slitherine
Slitherine
Posts: 495
Joined: Tue Nov 13, 2012 6:24 pm

Re: How to change fonts and texts (Unicode problem)

Post by AndrewGardner » Fri Jul 19, 2019 4:09 pm

The game engine used by Empires can display extended character sets. You have already figured out some of the steps, but I will outline the entire process for the benefit of others. Note that this requires adding and modifying files in the game installation, so changes could interfere with the normal function of the game, and game updates could undo you changes. For these instructions, I am using XXX as an example language code, replace it with a three letter code for the language you are targeting.

In the Core folder of the game install:
- Add your font in TTF format
- Add the EXTENDED.DAT file found here: https://www.dropbox.com/s/rx9h6j59cr5xz ... D.zip?dl=0
- Open LANG.TXT and add a line for the new language for the game to use, for example [XXX]

In the System folder of the game install, make a copy of the FONT.TXT file and name it FONT_XXX.TXT. In this copy:
- Add a line at the top "EXTENDED".
- For every font in the file, change the name line to refer to your font. So, if you added Core\myfont.TTF above, your FONT_XXX.TXT should start:

Code: Select all

EXTENDED

[DefaultFont]
height 12
name myfont

[TinyFont]
height 8
name myfont
...
In the Data\Text folder of the game install, you will find most of the text for the game. For each Text#.txt file in the folder that you wish to translate, copy the Text#.txt to Text#_XXX.txt. Then open the new file in a text editor and replace the English quoted text with your translations. There is additional text in the Text1.txt file of each scenario in Scenarios.

Also, in Text2.txt, add IDS_LANG_XXX,"My language", which will be shown in the language menu in English initially when switching languages.

There are also two textures used for the language:
Data\UI\Textures\langicon_xxx.tga - the flag shown in the language menu
Data\UI\Textures\lang_xxx.tga - the button shown on the main menu (one quarter of the image is used for each button state)

Then, when you start the game, you should be able to go to the language menu, select your new entry, and the game will display your translations. The main menu text is found in Text2.txt, if you want to quickly verify that characters are displaying correctly.

oooFUNooo
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 4
Joined: Sun Jun 23, 2019 8:33 am

Re: How to change fonts and texts (Unicode problem)

Post by oooFUNooo » Sat Jul 20, 2019 12:11 pm

Thanks a lot for your detailed explanation. I respect you and your company.

I followed the steps and succeeded in displaying Japanese characters with normal fonts.
However there is some trouble yet. About a half of all characters are shown, but the others aren't.
I found characters before U+6DB2 were seen and ones after U+6DB7 were not.
I guess EXTENDED.DAT may need some adjustment.

By the way, if I make a localization mod, can I share it with other players in this forum or elsewhere?

oooFUNooo
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 4
Joined: Sun Jun 23, 2019 8:33 am

Re: How to change fonts and texts (Unicode problem)

Post by oooFUNooo » Sat Jul 20, 2019 8:37 pm

Finally I succeeded in displaying all Japanese characters.
The cause of the trouble was mismatch between Japanese fonts and EXTENDED.DAT which defined printable characters.
I made my own EXTENDED.DAT included all characters with following Python script.

Code: Select all

data = []
for i in range(0x10000):
    data.append(i)
with open("EXTENDED.DAT", "wb") as f:
    for d in data:
        f.write(d.to_bytes(2, byteorder="little"))
Though it takes a few seconds to switch languages, I have no problem except that.
Thank you so much.

AndrewGardner
Slitherine
Slitherine
Posts: 495
Joined: Tue Nov 13, 2012 6:24 pm

Re: How to change fonts and texts (Unicode problem)

Post by AndrewGardner » Mon Jul 22, 2019 2:45 pm

I am glad to hear you got this working. I will pass along the information about EXTENDED.DAT, thank you for the details. You are very welcome to share your changes and additions with other players.

oooFUNooo
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 4
Joined: Sun Jun 23, 2019 8:33 am

Re: How to change fonts and texts (Unicode problem)

Post by oooFUNooo » Mon Jul 22, 2019 8:31 pm

Thanks a lot for your reply. I share a few problems and solutions.

Problem #1
I got texture related errors with some fonts when I used my own EXTENDED.DAT included all characters.

Solution #1
I altered my EXTENDED.DAT to include the minimum characters for Japanese texts.

Problem #2
I found weird characters at the bottom of a tooltip when the mouse was over a city.

Solution #2
I edited the lines 3810-3821 in Data/scripts/MapUI.bsf to fix it.

BEFORE:

Code: Select all

PrintCat(0, "<f%d>", $SMALLTOOLTIPFONT);
if (bAccess && gSelection.groupSelection <= 0)
{
    PrintStringLiteral("\n");
    PrintString("IDS_ACCESS_GARRISON");		
}
// if (bDetailed == FALSE)
// {
    // PrintStringLiteral("\n");
    // PrintString("IDS_CTRL_FOR_MORE");
// }
PrintStringLiteral("</f>");
AFTER:

Code: Select all

if (bAccess && gSelection.groupSelection <= 0)
{
    PrintCat(0, "<f%d>", $SMALLTOOLTIPFONT);
    PrintStringLiteral("\n");
    PrintString("IDS_ACCESS_GARRISON");		
    PrintStringLiteral("</f>");	
}
// if (bDetailed == FALSE)
// {
    // PrintStringLiteral("\n");
    // PrintString("IDS_CTRL_FOR_MORE");
// }

AndrewGardner
Slitherine
Slitherine
Posts: 495
Joined: Tue Nov 13, 2012 6:24 pm

Re: How to change fonts and texts (Unicode problem)

Post by AndrewGardner » Wed Jul 24, 2019 9:14 pm

I believe we will be able to fix the issue behind Problem #2 in the next update. It should be much simpler for you to share your translation mod if you don't need to change the BSF file as well.

Post Reply

Return to “MOD”