From 16b7b67c47d559cdfbabec831a073bbef008c7a7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 28 May 2013 11:12:39 +0200 Subject: [PATCH] Fixed problem with % processing on .po files. Fixed quote ' processing on I18N lib. --- app/src/processing/app/I18n.java | 22 ++++++++++++++++++---- app/src/processing/app/Sketch.java | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/I18n.java b/app/src/processing/app/I18n.java index 7ca442784..6c7c9079d 100644 --- a/app/src/processing/app/I18n.java +++ b/app/src/processing/app/I18n.java @@ -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); } diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 11f7034f6..ee1c82f78 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -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));