New i18n interface for KDE 4, second try

Nicolas Goutte nicolasg at snafu.de
Sun Oct 30 14:47:12 GMT 2005


On Sunday 30 October 2005 14:40, Chusslove Illich wrote:
(...)

> QString("%1 %1").arg("foo").arg("bar")
>
> results in "foo bar", while

Ooh, I have not know this trap!

>
> QString("%1 %1").arg("foo", "bar")
>
> results in "foo foo".
(...)
> To further empower the template solution, we can also dispense with
> formatting .arg() methods of QString:
>
> QString::arg(int a, int fieldWidth = 0, ...)
>
> used like:
>
> i18n("Directory %1: %2 MB").arg(dir).arg(size, 5) // dangerous
>

> by defining few small standalone matching functions:
>
> QString qarg (int a, int fieldWidth = 0, ...) {
>   return QString("%1").arg(a, fieldWidth, ...)
> }
>
> and using it in template call:
>
> i18n("Directory %1: %2 MB", dir, qarg(size, 5)) // safe

That is pretty much useless. If we go so far away from QString, we can 
directly use QString::number, which is static. (That would be better than to 
have QString-like arg functions but that do not work like QString::arg 
functions.)

Have a nice day!





More information about the kde-core-devel mailing list