The after build callback misuses the t() function.

You should not put variables directly in the first parameter because it is impossible to know what text will be in the variable so you cannot translate it.

Variables should be in the second param, but seeing as these are entirely variables, they shouldn't use t() at all.

Also another related rule is any content entered by the user shouldnot be run through t().

So in this case the t() calls should be removed.

Comments

mastoll’s picture

@rooby,

If you remove the the t() calls, what other function would you use to accomplish the same objective?

kopeboy’s picture

Yes please, @rooby
How should we then translate the titles?

rooby’s picture

You don't.

For example, the code should be like this:

<?php
drupal_set_title($node_add_title);
?>

This will be safe from malicious users because drupal_set_title() runs all text through check_plain() by default (although it give you to option to disable that in case you want to use filter_xss() or something instead).

Default drupal translation is only for text you hard code into your modules.
Anything that users enter is not translated.
If the user wants, they can enter the titles in another language.
For more information see https://www.drupal.org/developing/api/localization

From that page:

Important: do not localize user-provided content. The localization API is only for fixed strings in code. t() should never be called e.g. on a variable value that may contain user input.

If you have a site that you want to be in multiple languages then the user needs to be able to enter titles in multiple languages.

To do that you can use the internationalization module, which depends on the variable module.

Internationalization has string translation abilities so that you don't really have to do anything, however if you want to provide additional integration you can implement hook_variable_info() like is illustrated on the variable module project page.

nupur.lohokare’s picture

Assigned: Unassigned » nupur.lohokare
nupur.lohokare’s picture

Assigned: nupur.lohokare » Unassigned
Status: Active » Needs review
StatusFileSize
new1.32 KB

Hi rooby,

Found the issue you mentioned and removed the t() function from drupal_set_title().

Thanks
Nupur

anup.singh’s picture

Status: Needs review » Reviewed & tested by the community

Hi nupur.lohokare,

Patch looks good to me. Can be enrolled to Dev branch.

Thanks
Anup

  • jcmartinez committed 6bc8b14 on 7.x-1.x
    Issue #2184107 by roobi: Incorrect use of t() function
    
jcmartinez’s picture

Status: Reviewed & tested by the community » Fixed
jcmartinez’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.