I am just starting out in trying to mod Civ4, and I am learning some basic things that are probably elsewhere, but I haven't found them. I'll put some info here for those interested. If people have further info on the subject feel free to add to the thread. Eventually I'll add another "gem" of info.
Suppose you want to get some text. Of course you could put it into your code, but that is bad form, and would limit your code to the one language. Instead used localized text, that is, text in an .xml file that can include multiple languages and be more easily changed. The following is a snippet of an .xml text file. You can make them easily in notepad, just use all files type and add .xml to the file name.
I just left the English and Frech versions in, there are other languages of course. Be sure to add the first two lines and the last line to the file, then as many text tags as you wish. These text files must be in the "Text" folder of the "XML" folder of the "Assets" folder, just follow the example of other mods. Now if you want to put this text into your program, to put it in a popup box for example, you would do something like this:
getText uses the /TAG TXT_KEY_UNIT_SETTLER_STRATEGY to find the appropriate text. It would then put
"Build [COLOR_UNIT_TEXT]Settlers[COLOR_REVERT] to expand your empire with new cities."
into your variable theText (assuming your running Civ4 in English). The [COLOR_UNIT_TEXT] and [COLOR_REVERT] just tells Civ4 to highlight the word "Settlers" in the color reserved for units.
Ok so far? Just one more thing. Notice the () as the second parameter in getText(). It is a tuple that allows you to include more localized text into your text string. For example if the tagged text is the following:
your code that gets the text would look something like this
where who and victoryType are appropriate string variables that were assigned earlier. The string placeholders in your .xml file can have names. For example
is identical, the "_victor" and "_type" are ignored and are just there to make the meaning clearer.
I hope I got everything right, if not please let me know.
Edit: added needed parenthesis
Suppose you want to get some text. Of course you could put it into your code, but that is bad form, and would limit your code to the one language. Instead used localized text, that is, text in an .xml file that can include multiple languages and be more easily changed. The following is a snippet of an .xml text file. You can make them easily in notepad, just use all files type and add .xml to the file name.
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Civ4GameText xmlns="http://www.firaxis.com">
<TEXT>
<Tag>TXT_KEY_UNIT_SETTLER_STRATEGY</Tag>
<English>Build [COLOR_UNIT_TEXT]Settlers[COLOR_REVERT] to expand your empire with new cities.</English>
<French>Produisez des [COLOR_UNIT_TEXT]colons[COLOR_REVERT] pour étendre votre empire en fondant de nouvelles villes.</French>
</TEXT>
</Civ4GameText>
I just left the English and Frech versions in, there are other languages of course. Be sure to add the first two lines and the last line to the file, then as many text tags as you wish. These text files must be in the "Text" folder of the "XML" folder of the "Assets" folder, just follow the example of other mods. Now if you want to put this text into your program, to put it in a popup box for example, you would do something like this:
Code:
from CvPythonExtensions import * #this is in the global section
localText = CyTranslator() #as is this, it instantiates the Translator
# CyTranslator has the module to get the text
# you don't have to call it localText but that seems to be the convention
# try to follow conventions to make your code more readable
theText = localText.getText("TXT_KEY_UNIT_SETTLER_STRATEGY", ())
getText uses the /TAG TXT_KEY_UNIT_SETTLER_STRATEGY to find the appropriate text. It would then put
"Build [COLOR_UNIT_TEXT]Settlers[COLOR_REVERT] to expand your empire with new cities."
into your variable theText (assuming your running Civ4 in English). The [COLOR_UNIT_TEXT] and [COLOR_REVERT] just tells Civ4 to highlight the word "Settlers" in the color reserved for units.
Ok so far? Just one more thing. Notice the () as the second parameter in getText(). It is a tuple that allows you to include more localized text into your text string. For example if the tagged text is the following:
Code:
<English>%s1 has won a %s2 Victory!!!</English>
your code that gets the text would look something like this
Code:
theText = localText.getText("TXT_KEY", (who, victoryType,))
where who and victoryType are appropriate string variables that were assigned earlier. The string placeholders in your .xml file can have names. For example
Code:
<English>%s1_victor has won a %s2_type Victory!!!</English>
is identical, the "_victor" and "_type" are ignored and are just there to make the meaning clearer.
I hope I got everything right, if not please let me know.
Edit: added needed parenthesis