[haiku-development] Re: Patch reviews - help needed

  • From: Michael Pfeiffer <michael.w.pfeiffer@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 6 May 2010 17:23:01 +0200

Am 06.05.2010 um 16:08 schrieb Stephan Assmus:
> * The patch should ideally remove string composition:
> 
> BString errorString;
> errorString << "The file '";
> errorString fileName;
> errorString << "' cannot be found.";
> 
> should become:
> 
> char buffer[512];
> snprintf(buffer, sizeof(buffer), TR("The file '%s' cannot be "
>    "found."), fileName);
> 

For this case I prefer this solution:

BString buffer(TR("The file '%file' cannot be found."));
buffer.ReplaceFirst("%file", fileName);

Because then you don't have to worry about the size of the buffer
and in case there is more than one substitution variable their
order can be defined by the translator.

For example:
BString buffer(TR("%length %unit"));
buffer.ReplaceFirst("%length", "42");
buffer.ReplaceFirst("%unit", "mm");

In the translation it could be "%unit %length", I admit that is not
a good example.

- Michael


Other related posts: