I've been struggling for hours with a new kind of thing and I think I finally got it right - but I'm not even sure whether You like it (which might be more important than whether I like it myself)
The problem was localization of missions and campaigns, the solution I came up with covers much more than that and ended up being much more powerful then I intended it to be. That isn't a bad thing though.
And for all that I don't have a proper name for it..
Anyway, "the thing" works like this. Most strings (most filenames and displayed text, but not the author and background image) are passed through a converter that took me 3 hours to write.
Now I'm not going to explain
how it does it unless anyone asks me since it's a long story, but I'm going to explain
what it does.
It takes a string such as AllStrings{lang}.txt{23} and it spits out the string on the 23rd (starting at 0th) line of the file AllStringsen-GB.txt, or the file AllStringsnl-NL.txt or well it should be clear now. {lang} is replaced by the currently used language code.
That was the simple example, now comes the real work.
A valid localized-string is:
* a string that after pre-processing* does not contain { brackets } (literal string)
* a localized-string plus {index} where index is (after processing!) a decimal number
* a localized-string plus {xpath} where xpath is (after processing) a string that starts with a / (slash)
* a localized-string plus {} (brackets with nothing inside) I don't know what this is good for, but you can use it.
Anything else is
not a valid localized-string.
pre-processing:
All occurrences of {lang} {Lang} {language} and {Language} are replaced by the current language code.
All occurrences of {Author} are replaced by the name of the author of the campaign/mission (as specified in the campaign/mission) - you could use this (in combination with "http files") to make it harder to change the Author field for people who are not you, it won't be impossible though.
{Version} is replaced by the version of the campaign/mission
{Date} is replaced by the current date in dd-mm-yyyy format (dashes, day before month)
{Time} is replaced by the current time in hh:mm format (24h)
main processing:
Here is where the "(after processing!)" note comes into play. It means that you can nest indexers like so:
strings{strings{strings{0}}}
If the file "strings" contains:
- Code:
1
3
2
5[/quote]
Then the result would be 5. Which is not surprising, since first it will apply the index 0 to strings, resulting in 1, then it will apply the index 1 resulting in 3 and finally it will apply the index 3, resulting in 5.
The same trick works for xpaths.
"http" files are downloaded before they are used. Beware that they may be downloaded multiple times in the current implementation (if strings would be a http file it would have been downloaded 3 times) I don't expect this to be a bottleneck but if it is I may cache the file after downloading.
Known issues & limitations
Yes there are some..
Due to the way filenames are kept apart from literal strings, it's impossible to have a literal string that equals a filename except when the [i]entire[/i] localized-string is a literal string. This may sound a bit arcane, so as a rule of thumb: name your files such that you will not need their name for anything else than to refer to that file.
It's not possible to let the locations of markers depend on the language. This might not sound like a limitation at first, but if you recall that markers may be (mis)used to put [i]any[/i] picture on the campaign screen, and that you can change the file being used for that picture based on the language, it might be clear to you that the pictures may have a different size and as such might have to be moved a bit. But you can't do that. Transparency is fully supported though, so to solve this, just put a transparent edge around the pictures so that their "middle" remains at the same place (relative to their upper left corner, which is used for positioning)
Comments please :)