Excuse my cross-quote...
silnarm doesn't like it and wants to have another system.
I never said that
I was probably pushing for Lua to hard and came accross wrong. The whole Lua Vs XML discussion is actually quite irrelevant.
My main concern is that you may be making it harder for yourself than it needs to be. I know I did that a hell of a lot in my younger days, and still do occasionally now
Designing a whole sub-system might be more 'fun' but I'd prefer to look at what we have, what needs translating, and how we can get the job done as easily as possible. Don't start with a 'wish-list', start with a 'need-this-list'.
So anyway, I took the liberty of strolling through the xml loading code again...
These are the 'translatables' we need to collect:
tech-tree: [tech/tech.xml]
Translatables:
Tech-Tree name, directory name (or filename without extension)
Attack-Types, from xml
Armour-Types, from xml
resources: [tech/resources/]
Translatables:
Resource names, sub-directory names
Individual resource XMLs have no translatables
factions: [tech/factions/faction/faction.xml]
Translatables:
Faction name, directory name
XML contains no translatables
upgrades: [tech/factions/faction/upgrades/]
Translatables:
Upgrade names, sub-directory names
Individual upgrade XMLs have no translatables
units: [tech/factions/faction/units/unit/unit.xml]
Translatables:
Unit name, directory name
Levels, from xml
Slection-Sounds, from xml
Command-Sounds, from xml
Skills:
Skill name, from xml*
Skill sounds, from xml
Commands:
Command name, from xml
* Are skill names actualy ever displayed in game??
Here's where/how we collect it... (excuse my semi-pseudo-code)
[NB: this removes the OO style references to translatables I was using earlier, so there is no
duplication of strings in the translatables table.]
// 'Global' (probably in 'Lang', which is a singleton)
map<string,string> translatables;
TechTree::load( string &path ) {
string techname = getNameFromPath( path );
translatables[techname] = techname; // put in translation tables, with default value
// code gets directory names from /tech/resources
foreach ( string name in filenames ) {
translatables[name] = name;
}
// loads tech-tree Xml
foreach ( XmlNode node in AttackTypeNode.childen ) {
translatables[node["name"]] = node["name"];
}
// same for armour types...
// factions... names were passed in as a parameter, in GAE this is a set, I think vanilla Glest
// uses a vector.
foreach ( string name in factionNames ) {
translatables[name] = name;
}
// code loads factions...
}
FactionType::load() {
// code pre-loads unit and upgrade names...
foreach ( string name in (unitNames + upgradeNames) ) {
translatables[name] = name;
}
// code loads units
// code loads upgrades
}
UnitType::load() {
// code starts loading paramaters
if ( levelsNode ) {
foreach ( XmlNode node in levelsNode.children ) {
translatables[node["name"]] = node["name"];
}
}
// code loads more parameters...
// do something with command and selection sounds
// Code loads skills and commands
}
SkillType::load() {
// code gets stuff from xml
translatables[name] = name;
// sounds?
}
CommandTpye::load() {
// code gets stuff from xml
translatables[name] = name;
}
and so then you have all your translatables, you could write out a template file...
// create translation template...
FILE *fp = fopen( "translation_template.ini", "w" );
for ( map<string,string>iterator it = translatables.begin(); it != translatables.end(); ++it ) {
fprintf( fp, "%s=\n", it->first.c_str() );
}
fclose( fp );
or if this is a game, translate...
// or load translation...
for ( map<string,string>iterator it = translatables.begin(); it != translatables.end(); ++it ) {
string translation = Lang::getTranslation( it->first );
if ( translation.size() ) { // if not empty string
it->second = translation;
}
}
That's the best I could come up with. I think it's fairly minimal, clean, and perhaps most importantly, doesn't require modifying any existing XML.