Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add i18n support #49

Closed
grannypron opened this issue Jan 26, 2021 · 43 comments
Closed

Add i18n support #49

grannypron opened this issue Jan 26, 2021 · 43 comments
Labels
enhancement New feature or request
Milestone

Comments

@grannypron
Copy link
Owner

Integrate the gnu gettext library to support translation of hardcoded strings into different languages.

Discussion at http://ua.reonis.com/index.php?topic=4052.0

@grannypron grannypron added the enhancement New feature or request label Jan 26, 2021
@grannypron
Copy link
Owner Author

In terms of development, all strings must be marked with gettext() around them. And the #include <../i18n/libintl.h> must be included at the top of every file that uses that.

Two new dlls will need to be distributed with the .exe: iconv.dll and intl.dll. Maybe it's possible to statically link (I think that's the term) the source from gettext right into the exe which would just make the exe grow a little. Not sure - that would probably be a follow-on.

After all strings are marked with gettext, one would run xgettext on the code to generate a messages.po file that would be filled out by a translator. Then, one runs msgfmt to turn that messages.po into a binary messages.mo file and that is included in a new i18n subdirectory of the dsn directory - actually it would be a i18n/**/LC_MESSAGES/ subdirectory where ** is the local identifier like "en" or "fr".

@grannypron
Copy link
Owner Author

One problem is that some of the hardcoded strings are in global variables like the MENU_ENTRY StartMenu global variable. This initialization (and now its gettext lookup) happen very early in the initialization of the program - before the config file is loaded. So, at least for an IOC, we will use environment variables or parameters to start the .exe with localization settings.

@grannypron
Copy link
Owner Author

Another option that would not require "compilation" of po files might be https://github.com/garbageslam/spirit-po While this is non-standard and it doesn't seem to be active, this would allow people to change translation without running any external programs. Speed of execution is not too much of a concern here anyway since we are talking about turn-based games.

@grannypron
Copy link
Owner Author

The spirit-po project was very attractive, but it relied on including spirit boost which looked to me to be a HUGE library that I would have had to include in the project which was just not something that I think we wanted to do.

@grannypron
Copy link
Owner Author

This SO question provides a good overview and is left with gettext: https://stackoverflow.com/questions/2185568/alternatives-to-gettext

@grannypron
Copy link
Owner Author

I dug into trying to use https://github.com/kahrl/gettext-msvc/ to create statically linked libs of libintl and libiconv and I was able to compile them but ended up with unintelligible (to me) linker errors, which stopped me in my tracks:

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2001	unresolved external symbol __imp__mbrlen	UAFWin	...\src\UAFWin\libintl.lib(printf.obj)	1	
Error	LNK2001	unresolved external symbol __imp__wcrtomb	UAFWin	...\src\UAFWin\libintl.lib(printf.obj)	1	
Error	LNK2001	unresolved external symbol __imp__mbrtowc	UAFWin	...\src\UAFWin\libintl.lib(printf.obj)	1	
Error	LNK2001	unresolved external symbol __imp__setlocale	UAFWin	...\src\UAFWin\libintl.lib(setlocale.obj)	1	
Error	LNK2001	unresolved external symbol __imp__open	UAFWin	...\src\UAFWin\libintl.lib(loadmsgcat.obj)	1	
Error	LNK2001	unresolved external symbol __imp__open	UAFWin	...\src\UAFWin\OLDNAMES.lib(open.obi)	1	
Error	LNK2001	unresolved external symbol __imp__read	UAFWin	...\src\UAFWin\libintl.lib(loadmsgcat.obj)	1	
Error	LNK2001	unresolved external symbol __imp__read	UAFWin	...\src\UAFWin\OLDNAMES.lib(read.obi)	1	
Error	LNK2001	unresolved external symbol __imp__close	UAFWin	...\src\UAFWin\libintl.lib(loadmsgcat.obj)	1	
Error	LNK2001	unresolved external symbol __imp__close	UAFWin	...\src\UAFWin\OLDNAMES.lib(close.obi)	1	
Error	LNK2001	unresolved external symbol __imp__bsearch	UAFWin	...\src\UAFWin\libintl.lib(localealias.obj)	1	
Error	LNK2001	unresolved external symbol __except_handler4_common	UAFWin	...\src\UAFWin\MSVCRT.lib(chandler4gs.obj)	1	

@grannypron
Copy link
Owner Author

Continue to get linking errors when trying this build as well: https://osdn.net/projects/libintl-msvc10/downloads/63654/libintl-msvc10-0.2.2-gettext-0.19.5.1base.zip/

I am giving up on statically linking at this point.

@grannypron
Copy link
Owner Author

Initial attempt at a roll-your-own solution using JSON is commit df099d7

@grannypron
Copy link
Owner Author

@Reotor
Copy link

Reotor commented Jan 29, 2021

DungeonCraft_uaf_00049.zip

The developer suggests using the "messageMap.txt" file in the game "Data" folder to make translations by inserting original and translated strings into it according to a certain scheme..

This seems to work, but there are encoding problems:

Screenshot_2
Screenshot_1

When I change the encoding of the file "messageMap.txt", I get an error in the game:

Screenshot_4

Another problem is that the GENERAL GRAPHICS ERROR message displays in game apparently when the game accesses the "messageMap.txt" file:

Screenshot_5

GENERAL GRAPHICS ERROR message displays immediately after the first movement of the mouse cursor and does not disappear until you switch to another menu. If there is no translation, everything is fine, if the text is affected by this file, this message appears again after the movement of the mouse.

@grannypron
Copy link
Owner Author

The text displaying incorrectly is because the json reader only reads in UTF-8, and because the file is UTF-8, the Cyrillic characters are coded in Unicode with 2 bytes instead of one. The font doesn't have all the Unicode glyphs pre-rendered and the CDXBitmapFont::Draw* routines are only designed to write 8-bit (1 byte) characters (see #41) right now. I will have to translate backward to ANSI I think.

@grannypron
Copy link
Owner Author

Yep, translating back to ANSI with the routine here did the trick:

https://stackoverflow.com/questions/8298081/convert-utf-8-to-ansi-in-c/35272822#35272822

@grannypron
Copy link
Owner Author

DungeonCraft_uaf_00049_b.zip

@Reotor
Copy link

Reotor commented Jan 29, 2021

DungeonCraft_uaf_00049_b.zip

Huge THANKS! Now everything seems to be working fine! Working on interface translation ...

Screenshot_7

@Reotor
Copy link

Reotor commented Jan 30, 2021

While translating the interface, I found out that there are errors in the titles of multiclass characters in the character creation menu:

Screenshot_15

@grannypron
Copy link
Owner Author

grannypron commented Feb 1, 2021

@Reotor
Copy link

Reotor commented Feb 1, 2021

Considering that the work may take some more time, In case someone needs to test its functionality now, I will post the current version of the "messageMap.txt" here: messageMap.txt.

Except for in-game items and spells, the work is about 70-90% done (while I may be wrong and underestimate the scale of the game ...)

@grannypron
Copy link
Owner Author

DungeonCraft_uaf_00049_e.zip

@Reotor
Copy link

Reotor commented Feb 3, 2021

Here is the new file messageMap.txt:

messageMap.txt_002.zip

Some nuances:

  • Since it takes more space to translate some of the option names into Russian, I had to capitalize the text in most cases. And in order to make everything look symmetrical, I made the rest of the text of the option names the same.

  • It should be understood that this translation will definitely be supplemented and reworked (including with the help of the Russian-speaking community from our forums). Therefore, it cannot yet be called final.

  • Only the interface has been translated so far (where possible). Names of items, spells, etc. will be translated later.

  • As it was said before, I translated only what was possible, but some lines remained in the code and I do not know how it was originally written. Your help is needed here. For this purpose, I have inserted hints into the file.

@Reotor
Copy link

Reotor commented Feb 4, 2021

Here is a new file with new strings and markups added to find an opportunity to translate the unsuitable strings.

messageMap.txt_005.zip

For now, I will gradually add items, spells, etc. to the file.

@Reotor
Copy link

Reotor commented Feb 6, 2021

Here is the new version of the "messageMap.txt" file.

messageMap.txt_008 (all items translated).zip

Added and translated all in-game items (at least those that were in my "items.txt" file), as well as several new strings that I discovered during the game. Then I will translate spells, monsters, etc.

@Reotor
Copy link

Reotor commented Feb 10, 2021

New messageMap.txt here:

messageMap.txt_012 (all items and spells translated).zip

The names of all in-game spells have been translated, as well as new lines and some additional minor adjustments made. Now the translation of the names of the monsters is next...

@grannypron
Copy link
Owner Author

When you are all set and we are sure it is able to do all you need, lmk and I will cut a 5.28 release. Since you are the primary stakeholder on this atm!

@Reotor
Copy link

Reotor commented Feb 13, 2021

When you are all set and we are sure it is able to do all you need, lmk and I will cut a 5.28 release. Since you are the primary stakeholder on this atm!

So the new file is here!

messageMap.txt_013 (all items, spells, monsters translated).zip

The names of the game monsters have been translated into Russian. Now I need your help please in order to get to the text that is not possible to get with just this file ...

@Reotor
Copy link

Reotor commented Feb 14, 2021

Before the release of version 5.28, we need to deal with the translation of the text that I could not translate using the message.txt file

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 001:

001

It is necessary to provide the ability to translate without affecting the changing numbers. Is it possible to translate this text and how to do it?

I cannot enter this text with numbers into the "MessageMap.txt" file, as the numbers will constantly change. You can try to enter strings into the file for each new combination of numbers, but then you get just a huge number of combinations.

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 002:

002

Approximately the same as the previous problem....

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 003:

003

No matter how hard I tried to enter "attacks" word into the file, I could not get it translated...

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 004:

004

The same as the previous

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 005/006:

005
006

The same (for char stats menu when creating characters). Only "AVAIL" : "Есть:", worked

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 007:

010

(Chatacter Name) successfully wrote (Spell Name) into the spellbook." : "",

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 008:

011

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 009:

012

@Reotor
Copy link

Reotor commented Feb 14, 2021

Problem № 010:

013

@Reotor
Copy link

Reotor commented Feb 14, 2021

So far, that's all I've noticed. I ask for help, thanks

@grannypron
Copy link
Owner Author

Yeah I think just about all of these will require minor code changes. The strings are hardcoded in and appended together before they are passed to the DisplayText methods. I think number 6 might be able to be done by putting /GSTR or some number of spaces after STR but the rest will have to be minor code changes.

@grannypron
Copy link
Owner Author

For number 4, check out [TimeText] in specialAbilities.txt

@grannypron
Copy link
Owner Author

Number 5 is in Global_Display in specialAbilities.txt

@Reotor
Copy link

Reotor commented Feb 15, 2021

001, 002, 004, 008, 009, 010 ! SOLVED ! Thank you very much!

003, 005, 006, 007 still can't fix...

@Reotor
Copy link

Reotor commented Feb 15, 2021

005/006 SOLVED, TY!

005, 006 SOLVED

@Reotor
Copy link

Reotor commented Feb 15, 2021

All the rest problems with translation for current moment SOLVED, TY! I need some more time to identify any other similar translation problems...

@Reotor
Copy link

Reotor commented Feb 19, 2021

@grannypron
Copy link
Owner Author

Closing. Any other i18n tweaks should be filed under separate tickets.

@grannypron grannypron added this to the 5.28 milestone Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants