single quotes in translation values

In 3.1@5098, Rodney replaced a bunch of doubled single quotes in VASSAL.properties with single single quotes. Looking back through the change log for that file, I can see that this not the first time we’ve removed doubled single quotes, nor have we added them only a single time, either.

Which way is correct? Why did we add them in the first place?

Ok,

I have finally worked out what is going on here. This has been bouncing back and forwards for years.

Currently, if a property string does not contain any {n}'s, then it must be encoded with single quotes. If the property does contain any {n}'s, then it must be encoded with double quotes.

The problem is being caused by the MessageFormat class which is used to evaluate the {n} strings via the Resources.getString(String, args) call - It strips one layer of quotes. Strings without {n}'s are evaluated using Resources.getString(String) and do not need to generate a MessageFormat and so only need single quotes.

Confusion over the years as to which strings actually needed double quotes has caused a sort of trial and error ping pong game of single and double quoting of various strings to fix problems as they where noticed. Since many error messages are rarely seen, the problem has been cropping up on and off at odd times.

I see several possible solutions:

  1. Do nothing to the code, educate developers and translators on when to use single and when to use double quotes (yuck).

  2. Change Resources.getString(String) to evaluate using a MessageFormat even though it does not need to. This will mean that ALL quotes ALWAYS need to be double quoted. (Mostly yuck, but at least consistent).

  3. Do something cleverer. Change all double quotes to single quotes in the .properties files and have Resources.getString(string, args) inspect the string to be evaluated and double any quotes before creating the MessageFormat. This will mean that ALL quotes ALWAYS need to be single quoted. (Less efficient, but far more logical for developers and translators).

Thoughts?

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

#1 is what we have now. #1 clearly does not work.

#2 forces us to remember the double-quoting convention, and so most likely
will cause single single quotes to creep back in.

I’m not certain that we need something cleverer, though. Do we use any of
the features of MessageFormat except the ability to substitute in arguments?
If not, then we could use String.format() for argument substitution instead.
String.format() is basically just sprintf() with slightly different format
specifier syntax.

String.format(“Blah blah %1$s blah blah %2$s”, “foo”, “bar”);

will give you “Blah blah foo blah blah bar”.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

No, just straight replacement of {0}, {1}, {2} etc with the matching arguments. There used to be a date conversion, but it has been removed because it was too confusing for the translators.

Good idea.

Or we could just do the replacement of the format we use now ({n}'s) directly ourselves. We know the number of arguments supplied, so we know home many {n}'s there are.

Keep it simple…The translators are used to {0}, {1}, {2}… and it makes more sense than %1$s - Someone is bound to forget the $s somewhere along the line.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

We can’t do straight replacement, as then we have no way of escaping curly
braces. ‘{{0}}’ would fall down badly, e.g.

I think we should go with this, as sprintf format syntax is pretty much
standard across languages these days. This way, the sole character which
needs escaping is ‘%’, which you write as ‘%%’. The percent sign is far, far
less common in messages than the single quote, so there’s less potential for
mistakes.

The only format specifier our translators will need is ‘%n$s’. The ‘%’ starts
a format specifier, the ‘n$’ is the arugment index, and the ‘s’ is the string
type. Any non-strings are converted automatically (like they are now), so ‘%s’
is all we’d need unless we want to do fancy things like have zero-padded
numbers or something. The totality of the instructions for translators would
amount to “Use ‘%n$s’ where you would have used ‘{n}’ before.”

GNU gettext, which is used for i18n for a huge number of C/C++ programs,
uses exactly this format, which means that this is the format which a
majority of the translators in the world are using. Some of our translators
might already be familiar with sprintf (I think Torsten, our German
translator, is), and for the ones who aren’t, then they’re learning
something which is standard across the whole computing world and not just
idiosyncratic to VASSAL.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

You’ve convinced me, go for it. Though there is no need to escape { or } in any of our current messages, we don’t use them in any message text.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Using {n} is not specific to VASSAL. It’s the standard for Java. I would prefer to stick with the Java standard if we can. Unfortunately, it seems they realize that they have a problem. Check out the warning in http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html
Warning: The rules for using quotes within message format patterns unfortunately have shown to be somewhat confusing. In particular, it isn’t always obvious to localizers whether single quotes need to be doubled or not. Make sure to inform localizers about the rules, and tell them (for example, by using comments in resource bundle source files) which strings will be processed by MessageFormat. Note that localizers may need to use single quotes in translated strings where the original version doesn’t have them.

Yuck!
rk

Post generated using Mail2Forum (mail2forum.com)

Except where the standard Java is complete crap, in which case I see no problem with using a rest-of-the-world standard to achieve the same end.

The actual core messages are only ever created by developers, not by module designers or translators, so there should not be a problem there.

Even an un-trained translator will not try to translate {0} or %0$s into anything else and leave them unchanged - I don’t think it will cause any long term support issues.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake Rodney Kinney:

It would be worse if they didn’t realize they have a problem. If this quoting
style were not irretrievably broken, I would say that we should stick with
it, too. But it’s not fixable.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)