Fixed problem with % processing on .po files. Fixed quote ' processing on I18N lib.

This commit is contained in:
Cristian Maglie 2013-05-28 11:12:39 +02:00
parent 3394f61276
commit 16b7b67c47
2 changed files with 20 additions and 6 deletions

View File

@ -46,15 +46,29 @@ public class I18n {
}
public static String _(String s) {
String res;
try {
return i18n.getString(s);
}
catch (MissingResourceException e) {
return s;
res = i18n.getString(s);
} catch (MissingResourceException e) {
res = s;
}
// The single % is the arguments selector in .PO files.
// We must put double %% inside the translations to avoid
// getting .PO processing in the way.
res = res.replace("%%", "%");
return res;
}
public static String format(String fmt, Object ... args) {
// Single quote is used to escape curly bracket arguments.
// - Prevents strings fixed at translation time to be fixed again
fmt = fmt.replace("''", "'");
// - Replace ' with the escaped version ''
fmt = fmt.replace("'", "''");
return MessageFormat.format(fmt, args);
}

View File

@ -1634,12 +1634,12 @@ public class Sketch {
long textSize = sizes[0];
long dataSize = sizes[1];
System.out.println(I18n
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum) - {2}% used"),
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum) - {2}%% used"),
textSize, maxTextSize, textSize * 100 / maxTextSize));
if (dataSize >= 0) {
if (maxDataSize > 0) {
System.out.println(I18n.format(
_("Minimum Memory usage: {0} bytes (of a {1} byte maximum) - {2}% used"),
_("Minimum Memory usage: {0} bytes (of a {1} byte maximum) - {2}%% used"),
dataSize, maxDataSize, dataSize * 100 / maxDataSize));
} else {
System.out.println(I18n.format(_("Minimum Memory usage: {0} bytes"), dataSize));