Singular and Plural for XML of Texts

raystuttgart

Civ4Col Modder
Joined
Jan 24, 2011
Messages
9,672
Location
Stuttgart, Germany
Hi guys,

I am currently trying to figure out something in XML.
(Related to text.)

Since I it might be useful for many mods, why not figure it out together. :)

Example:
(Simplified)

Code:
<TEXT>
	<Tag>TXT_KEY_FATHER_FREE_UNITS</Tag>
	<English>Provides %d1 %s2:2</English>
		...
</TEXT>

Where %d1 is the amount and %s2:2 is referring to the plural case of entries for Units like this:
Code:
<Text>Master Carpenter:Master Carpenters</Text>

This piece of XML will always generate text (e.g.) in Colopedia that says:

* Provides 4 Master Carpenters (if 4 units given)
or
* Provides 1 Master Carpenters (if only 1 unit given)
or
...

So obviously it always uses plural.
Which is not a big deal, but it simply looks a bit stupid if there is only 1 unit provided.

Well, it would not be that hard to code into DLL that in case of singular it should use a different text key, than in case of singular.

So we could have:
TXT_KEY_FATHER_FREE_UNITS_SINGULAR
TXT_KEY_FATHER_FREE_UNITS_PLURAL

But there must be a better solution than that. :)
(I don't want to duplicate every text, where I could have singular and plural case.)

Also, there does exist the NUM modifier in such Text-XML.
(It simply does not work here.)

Example:
Code:
<English>Growing (%d1 [NUM1:Turn:Turns])</English>

But if I try to write something like this, it seems to get confused because of the many ":" ...

Code:
<TEXT>
	<Tag>TXT_KEY_FATHER_FREE_UNITS</Tag>
	<English>Provides %d1 [NUM1:%s2[COLOR="Red"]:[/COLOR]1:%s2[COLOR="Red"]:[/COLOR]2]</English>
		...
</TEXT>

This engine simply too stupid to understand something like this:
[NUM1:%s2:1:%s2:2]

Meaning to translate into something like this:
1 -> Master Carpenter
>1 -> Master Carpenters

----------

Any ideas to get singular and plural into such a simple text as this one without messing with DLL ? :think:
(Meaning, if "%d1" == 1, then use "%s2:1" instead of "%s2:2".)

Code:
<TEXT>
	<Tag>TXT_KEY_FATHER_FREE_UNITS</Tag>
	<English>[ICON_BULLET]Provides %d1 %s2:2</English>
		...
</TEXT>
 
While your working on this maybe you could write in the code we previously discussed which allows more than 2 units to be consumed for the production of a single unit. For example, Gunsmith would consume 10 iron ores and produce 1 musket. Not possible currently, but if it were possible I could introduce a very powerful mods mod to the community. Just sayin...
 
Where %d1 is the amount and %s2:2 is referring to the plural case of entries for Units like this:
Code:

<Text>Master Carpenter:Master Carpenters</Text>

This piece of XML will always generate text (e.g.) in Colopedia that says:

* Provides 4 Master Carpenters (if 4 units given)
or
* Provides 1 Master Carpenters (if only 1 unit given)
or
...

So obviously it always uses plural.
Which is not a big deal, but it simply looks a bit stupid if there is only 1 unit provided.

Hmm I hadn't noticed that but you're right.

edit:
nevermind! I wrote an explanation I realized was wrong! :P

I don't know if they implemented this, but if another kind of separator like :: had higher precedence then something like this could work
<English>Provides %d1 [NUM1::%s2:1::%s2:2]</English>

or if nested brackets were supported
<English>Provides %d1 [NUM1:[[%s2:1]:[%s2:2]]]</English>

I'm supposing nothing like that was implemented, in which case it would indeed require dll hacking to be truly possible to use xml plural/singular appropriately.

edit: Ray, If I remember right German nouns can be feminine, masculine or neuter in addition to singular or plural, it must really be complicated to try to get it to state all those correctly! :crazyeye:
 
Actually in this case the gender does not matter.
(It is already taken care of in the TXT_KEY of the Unit.)

I would only need some way of selecting singular or plural of %s2, depending on actual number in %d1.

So
%d1 == 1 --> %s2:1
%d1 > 1 --> %s2:2

But it does not seem to be possible in XML itself.
(And I don't think it is worth modifying DLL because of it.)
 
I have wondered about this myself. In some TXT entries I have seen things like:

<English>Carpenter:Carpenters</English>

And I had just assumed that the game differentiated between singular and plural as necessary.

But now that you point this out, it doesn't surprise me that it doesn't.
 
Alright, sorry to ask but I want to be sure to understand how works variables in XML texts.

So from what I've understood (tell me if I'm wrong):
  • %### designates variables.
  • %d## designates a digit variable.
  • %s## designates a string variable.
  • %d1## designate the rank of the variable (I guess as determined somewhere else)
  • There could be a name, as for instance #s1_CivName to specify which text is used

Now about the [NUM#:xxx:yyy] stuff.
Code:
[COLOR="Blue"]<English>[/COLOR]Maximum %d1 [NUM1:unit:units] per settlement[COLOR="Blue"]</English>[/COLOR]
will write "1 unit", "2 units", "3 units"... depending of the number shown. What you say is that this can work only for plain text and not in using variables within the [NUM] tag. Granted.

However, in the Spanish text, we can find stuff like that:
Code:
[COLOR="Blue"]<Spanish>[/COLOR]El asentamiento debe trabajar para convertirse en [NUM1:un:una:unos:unas] %s1_ImpName[COLOR="Blue"]</Spanish>[/COLOR]
Does that mean it can adapt the [NUM] text according to the gender? What I mean is:
if %s1 is singular feminine => then will be used "una"

There's no variables to be read inside the [NUM1] tag so XML can't be lost with ":" characters. It only needs to check the gender of %s1 string as specified in those lines:
Code:
[COLOR="Blue"]<Spanish>[/COLOR]
	[COLOR="Blue"]<Text>[/COLOR]gran plantación[COLOR="Blue"]</Text>
	<Gender>[/COLOR]Female[COLOR="Blue"]</Gender>
	<Plural>[/COLOR]0[COLOR="Blue"]</Plural>[/COLOR]
[COLOR="Blue"]</Spanish>[/COLOR]

I haven't tested to check if the Spanish text work well this way. The feature doesn't seem to be used in the original French translation though. Maybe it just doesn't work?

I've made an attempt by myself for French which didn't work, as stated here:
http://forums.civfanatics.com/showpost.php?p=13193623&postcount=2365
 
So from what I've understood (tell me if I'm wrong):
  • %### designates variables.
  • %d## designates a digit variable.
  • %s## designates a string variable.
  • %d1## designate the rank of the variable (I guess as determined somewhere else)

Correct.

About the numbering:

%d1### or %s2### is simply the order the DLL fills the variables.
DLL has to know which value to put into which place of the string.

[*]There could be a name, as for instance #s1_CivName to specify which text is used

The DLL programmer decides in his code about that.
He will put whatever variable he wants into variable 1.
(He will mark the corresponging varible in XML as %s1)

%s1_CivName --> The DLL modder simply tells the XML modder: This is supposed to be the name of the Civ.

Considering functionality it would make no difference if the variable would be called %s1_IDontCareToGiveItASpeakingName or simply %s1.
You would simply need to go inside of the DLL source code to find out, what is going to be filled into that variable.

Please understand:
There is no real logic in XML.
All of the real logic is inside of the DLL.

Now about the [NUM#:xxx:yyy] stuff.
Code:
[COLOR="Blue"]<English>[/COLOR]Maximum %d1 [NUM1:unit:units] per settlement[COLOR="Blue"]</English>[/COLOR]
will write "1 unit", "2 units", "3 units"... depending of the number shown. What you say is that this can work only for plain text and not in using variables within the [NUM] tag. Granted.

Correct.

Maybe it just doesn't work?

It does work ... sometimes.

1. The TXT_KEY used to fill needs to correctly specifies gender and singular/plural as in your example.
2. And sometimes the XML needs to correctly specify which case to use. (e.g. %s2:2)

That is why you also have TXT_KEY definitions like this:

Code:
<French>
	<Text>Forêt clairsemée:Forêts clairsemées</Text>
	<Gender>Female:Female</Gender>
	<Plural>0:1</Plural>
</French>

To be explicitly referenced as %sX:1 or %sX:2.

Or:
Code:
<Italian>
	<Text>Incaico:Incaica:Incaici:Incaiche</Text>
	<Gender>Male:Female:Male:Female</Gender>
	<Plural>0:0:1:1</Plural>
</Italian>

To be explicitly referenced as %sX:1 or %sX:2 or %sX:3 or %sX:4.

-------------

Edit:

A lot of the time, the TXT_KEYs are simply not correctly set up to allow referencing of the cases.
 
I think it requires more than that.

Just to be sure I was editing the correct lines, I've changed my text to something totally different:
Code:
<Tag>TXT_KEY_CIV_FRANCE_SHORT_DESC</Tag>
<English>New France</English>
<French>
	<Text>TXT1:TXT2</Text>
	<Gender>Female:Female</Gender>
	<Plural>0:1</Plural>
</French>

Then I've set up the %s2:2 to check if TXT2 was called.

Code:
<Tag>TXT_KEY_MISC_CONTACT_LEADER</Tag>
<English>Contact %s1_PlyrName of %s2_CivName</English>
<French>Contacter %s1_PlyrName des %s2:2_CivName</French>

It turns out that it's not the case, it's "TXT1" which appears.

plural_text_use.jpg


But anyway, we're wasting our time. As you've said from start, let's get over it.
 
Actually the case you currently try is usually not the problem and should work. :confused:
(But your definition seems correct.)

The problem is to have some kind of definition in XML to switch between gender or singular/plural cases of a variable depending on another (second) variable.
(This does not work correctly and would need to be done in DLL.)

But anyway, we're wasting our time. As you've said from start, let's get over it.

It is never a waste of time, if you learn something.

But well yes, the system for defining gender and plural/singular in XML is pretty crappy and I have kind of given up on it as well.
 
Speaking of languages, I wrote something in this regard for M:C, which other people may find interesting as well.

In short it is a way to add new translations using XML only. Also each TXT only needs <english>. Any other will be a bonus, but will revert to English if selected language is missing.

Description: http://forums.civfanatics.com/showthread.php?t=523899

The actual code: https://github.com/Nightinggale/Medieval_Tech/commit/216b1041c1725da05e7f5859455b159f44e1ac3b

Feel free to use this if you like.

But well yes, the system for defining gender and plural/singular in XML is pretty crappy and I have kind of given up on it as well.
If you give a German string, where gender is broken, then I might take a look eventually. The same goes for plural (the carpenter string example is enough here). It might not be the next on the list, but that isn't the same as it will never happen.
 
Back
Top Bottom