开发者

t() function does't add the string to the translation interface

i use customfiel php code inside one of my views to translate a string since 2.x of views is bad at localization. i use the following php code:开发者_如何学编程

echo t('Watch Video');

but the string does not appear in the "translate interface" section.

thanks for your help.

lukas


The accepted answer is wrong, as the localization script is not scanning anything. The string is registered in the translate interface as soon as it gets passed through the t() function for the first time in the non-standard language.

Therefore, for translation it doesn't matter if the code you are writing is eval'd (interpreted from the database) or exists in the source. Obviously good practice would be to keep code in files where it belongs.

This blog post describes what needs to be done to get your strings into the translate interface.


The localisation database is built by scanning the source code, looking for instances of the t() function (and Drupal.t() in Javascript).

If the code in question has been entered into a text box in the Drupal admin area, then it isn't in the source code, so it won't be picked up by the localisation process.

For this reason (and others), you should put as little code as possible into the admin text boxes. There is usually an alternative way to achieve the same thing, but even if there isn't, you should reduce the code to a minimum -- best practice would be to have nothing there except a single line function call: have it call a function, and write the function code in your module or theme. That way it will be parsed when you run the localisation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜