This update adds an interface for implementing multilingual functionality to the game. Due to the unfinished translation work, some content is temporarily missing, but it is harmless, the interface has been completed. I will continue to finish Chinese translation.
How to Add a New Language
Create a language directory: Create a copy of the en folder under the data folder and rename it to the name of the language you need, assuming it is language_name. (Due to the unfinished translation work, some content is temporarily missing.)
Copy font files: Add the font files required for your language in ttf format under the fonts folder.
Import font files: Modify the contents of data/language_name/fonts_description.py and change the name of the font file to the name of the font file you need.
Add language button: Modify the content of the element_grid list in the create_choose_language_menu function in menu_creater_manager.py. Add a button with your language's full name as title and language_name as callback. For example:
Strings, function outputs, and dictionaries in text.py.
The content of each txt file under data/language_name/maps/level_number.
Some content in each map_properties.tmx file under data/language_name/maps/level_number, including:
The value of level_name.
The value of main_mission_description.
The value of limited_mission_description (if it exists).
Some content in some xml files under data/language_name/.
The content within the <talk> tag in characters.xml.
The content within the <info> tag in alternations.xml.
The content within the <info> tag in items.xml.
The content within the <info> tag in skills.xml.
Please note that the format of the above changes must be: <language_name> translated content </language_name>. For example:
...
<interaction>
<talk>
<en> Hurry up ! Leave ... the necropolis. </en>
<zh_cn> 快呀!从...进入墓地。</zh_cn>
</talk>
<talk>
<en> The clock is ticking... original place. </en>
<zh_cn> 时钟在滴答...回原来的地方。 </zh_cn>
</talk>
</interaction>
...
Changes and Explanations
Created src/gui/language.py to handle language-related matters. language.py will import the corresponding text.py according to the language in saves/options.xml.
Moved all static strings involving output in all files to variables in text.py, with variable names composed of uppercase letters and underscores of English content of strings. If the last character of a variable name is an underscore, it means that there is a colon at the end of the string.
Moved all contents involving variables and output in all files to be processed as functions in text.py.
Corresponded all contents involving class names and output in all files with dictionaries in text.py. (The original processing method is temporarily retained for English)
Changed the method of reading <info> or <talk> tags from xml files under the data folder. Added <language_name> tag. (But still retained the original processing method because translation work has not been completed)
Added code related to restarting games in main.py. Used to restart games after adjusting languages. Since I couldn't find a better way to restart games, I used creating subprocesses to implement game restart functionality.
Changed return value type of variable passed to quit_game in each Scene to int. And modified contents of function test_exit_game in test_start_screen.py (modification is very small, just changing True to 1)
When quit_game == 2 restart game
When quit_game == 1 exit game
When quit_game == 0 loop continues
Created src/gui/info_box.py to rewrite InfoBox class. This is because there is a Close button in InfoBox, and I couldn't find a better way to change its text.
Multilingual Support Description
Introduction
This update adds an interface for implementing multilingual functionality to the game. Due to the unfinished translation work, some content is temporarily missing, but it is harmless, the interface has been completed. I will continue to finish Chinese translation.
How to Add a New Language
en
folder under thedata
folder and rename it to the name of the language you need, assuming it islanguage_name
. (Due to the unfinished translation work, some content is temporarily missing.)fonts
folder.data/language_name/fonts_description.py
and change the name of the font file to the name of the font file you need.element_grid
list in thecreate_choose_language_menu
function inmenu_creater_manager.py
. Add a button with your language's full name astitle
andlanguage_name
ascallback
. For example:text.py
.data/language_name/maps/level_number
.data/language_name/maps/level_number
, including:data/language_name/
.<talk>
tag incharacters.xml
.<info>
tag inalternations.xml
.<info>
tag initems.xml
.<info>
tag inskills.xml
. Please note that the format of the above changes must be:<language_name> translated content </language_name>
. For example:Changes and Explanations
src/gui/language.py
to handle language-related matters.language.py
will import the correspondingtext.py
according to the language insaves/options.xml
.text.py
, with variable names composed of uppercase letters and underscores of English content of strings. If the last character of a variable name is an underscore, it means that there is a colon at the end of the string.text.py
.text.py
. (The original processing method is temporarily retained for English)<info>
or<talk>
tags from xml files under thedata
folder. Added<language_name>
tag. (But still retained the original processing method because translation work has not been completed)main.py
. Used to restart games after adjusting languages. Since I couldn't find a better way to restart games, I used creating subprocesses to implement game restart functionality.quit_game
in eachScene
to int. And modified contents of function test_exit_game in test_start_screen.py (modification is very small, just changing True to 1)Option menu
.