Does the order of placeholders matter when translating?

Asked by pete

Does the order of the placeholders matter when translating?

for example will it matter if I change the order of placeholders in the following strings when translating?

1. This is a live ${MEDIA_TYPE} for ${DISTRIBUTION_NAME} ${DISTRIBUTION_VERSION}

2. %(appname)s until %(support_end_month_str)s %(support_end_year)s

3. %'dnd link to %s

please help, I was just begining translations.

thanks
Pete

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Translations Edit question
Assignee:
No assignee Edit question
Solved by:
Milo Casagrande
Solved:
Last query:
Last reply:
Revision history for this message
Milo Casagrande (milo) said :
#1

Hi pete,

2010/2/26 pete <email address hidden>:
> New question #102465 on Ubuntu Translations:
> https://answers.launchpad.net/ubuntu-translations/+question/102465
>
> Does the order of the placeholders matter when translating?

It depends on the strings.

> for example will it matter if I change the order of placeholders in the following strings when translating?
>
> 1.   This is a live ${MEDIA_TYPE} for ${DISTRIBUTION_NAME} ${DISTRIBUTION_VERSION}
>
> 2.   %(appname)s until %(support_end_month_str)s %(support_end_year)s

In this last case, no, it doesn't matter where you move the
placeholders. That's usually Python syntax and the "name" of the
placeholders are there for this purpose: to move them as you need, but
you don't have to translate what's in between the parenthesis. I'm not
sure about the first case, but it should be safe to arrange them too
(is it C code? Need to check better).

> 3.   %'dnd link to %s

In this case it is necessary to keep the order, or you need to set the
position of the elements like this (this is usually C code):
%2$s YOUR_TRANSLATED_TEXT %1$'dnd

--
Milo Casagrande <email address hidden>

Revision history for this message
pete (subash-chathu) said :
#2

Hi Milo,

Thanks for the answer.

Can you please explain how to do the thing you mentioned for the 3rd string.

regards,
Pete

Revision history for this message
Best Milo Casagrande (milo) said :
#3

Hi pete,

2010/2/26 pete <email address hidden>:
> Hi Milo,
>
> Thanks for the answer.
>
> Can you please explain how to do the thing you mentioned for the 3rd
> string.

Basically it works this way.
If you have an original English string like this one:
Move %s in %s

You can reorder the positions of the two %s placeholder adding a
"positional information":
Move into %2$s %1$s

This is done because in language like C, you would have in the code
something like this:
printf("Move %s in %s", string1, string2);

And you tell the code to use first, the second string (string2), and
then string1.

You can also do that with all the other placeholders.

Another example:
File number %d in %s
In %2$s, file number %1$d

The C code would be something like this:
printf("File number %d in %s", number, string);

Here you can not just switch the position of the placeholders, because
the C code expects first a number, and then a string.

Ciao.

--
Milo Casagrande <email address hidden>

Revision history for this message
pete (subash-chathu) said :
#4

Thanks Milo Casagrande, that solved my question.