[haiku-i18n] Re: Localization: trailing spaces issue (Was: [haiku-commits] r40476 - haiku/trunk/src/apps/launchbox)

  • From: Adrien Destugues <pulkomandy@xxxxxxxxxxxxxxxxx>
  • To: haiku-i18n@xxxxxxxxxxxxx
  • Date: Sun, 13 Feb 2011 15:18:59 +0100

Le 13/02/2011 15:05, Siarzhuk Zharski a écrit :
Hi, Adrien,

On Sun, 13 Feb 2011 14:09:40 +0100, Adrien Destugues wrote:
Le 13/02/2011 13:57, Siarzhuk Zharski a écrit :
On Sun, 13 Feb 2011 11:26:06 +0100 (CET), zharik@xxxxxx wrote:
-            BString name(B_TRANSLATE("Pad "));
-            name << i + 1;
+            BString name(B_TRANSLATE("Pad"));
+            name << " " << i + 1;
Now about the "fixing" it in the source code. From my point of view this is just useless obfuscation and should be prohibited.

It's actually bad practise to use this form at all.

Some languages may require the space, other may not, other may want
i+1 << "Pad" or even "something" << i+1 << "somethingmore"

The proper solution is :
BString name(B_TRANSLATE("Pad %pad"));
name.ReplaceFirst("%pad",i+1);

Yes, I'm also unhappy, that BString has no single-call powerful formatter with printf-like syntax. :-D The problem in your implementation is that "i" is an integer and at least two "thrash" strings must be added to format it to string. :-(

Patches welcome :)
It was the plan to add this feature to BString, but noone did it yet.

The ReplaceFirst way has the advantage of allowing free-form identifiers, which convey more meaning than numbers. Printf would have to be used with position markers, so that args can be swapped if the translation needs so.

For example : BString progress(B_TRANSLATE("%files of %total")); is easier to manage than "%s of %s" in standard printf form, both for code readability and translation purposes. So, I think the simplest way would be to add ReplaceFirst variant taking an int, float, ... as parameter. As a bonus, this would allow actually formatting the number according to the locale rules as set in the preflet : thousand separator, decimal separator, and others.

--
Adrien.

Other related posts: