Translations and @locale comments

4 views
Skip to first unread message

Matt Read

unread,
Oct 28, 2010, 12:24:57 PM10/28/10
to habar...@googlegroups.com
@locale comments that you can add to the code work like the following:

// @locale some text explaining the context of the following string
_e('pith path ponies in the bath');


Then the @locale comment block will show in the translation template
so translators have a bit of context for translating things; instead
of just seeing some random string and the location of that string in a
file.

This would be particularly useful when you have printf style strings like:

_t(''moved %s blocks to %s.');

moved what to what? give the translator some help with a little context

// @locale the first placeholder string is the colour of the
block, while the second is bin name. eg. "moved red blocks to trash"
_t(''moved %s blocks to %s.');

I beat you thought the first placeholder was the number of blocks,
didn't you? :P

--
Matt Read
http://mattread.info
http://mattread.com

Owen Winkler

unread,
Oct 28, 2010, 12:46:34 PM10/28/10
to habar...@googlegroups.com
On 10/28/2010 12:24 PM, Matt Read wrote:

> _t(''moved %s blocks to %s.');
>
> I beat you thought the first placeholder was the number of blocks,
> didn't you? :P

No, because it's a %s instead of a %d. But I did think it caused an
error as written.

Also note that you don't need to use sprintf() with _t() anymore.

You can specify the substitutions as an array in the second parameter:

_t('moved %s blocks to %s', array('red', 'trash'));

This is still compatible with the module specifier as long as you pass
the substitutions as an array:

_t('moved %s blocks to %s', array('red', 'trash'), 'mymodule');

Note that you *must* specify the substitutions as an array, even if
there is only one:

_t('moved %d blocks', array(4)); // Correct
_t('moved %d blocks', 4); // Causes cancer in rats

Owen

Reply all
Reply to author
Forward
0 new messages