Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Drupal t() function and translations

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 355
    Comment on it

    syntax :

    t($string, array $args = array(), array $options = array())

    Every string that may be displayed to a user should be wrapped in the t() function actually it takes the responsibility for translating strings from one language into other not only this it also helps to prevent from malicious attack coming through variables


    If your site support multi language i.e more languages are enabled and the user's language is something other than English, t() will attempt to replace the English language string with a string in the appropriate language.


    Remember if no language support is enabled and no second argument is passed to t() , it simply returns the string without altering it.


    t() function should always be given a literal string for its first argument. print t('Welcome, @user', $values);


    How t() function is different from simple php variable print?


    for example in php if we do print "Welcome, $username."; it will replace $username with the value of the $username variable. But real scenario it will open your code to be attacked by malicious user to inject JavaScript or other code into the output


    The t() function provides an alternate, and more secure, method for replacing placeholders in text with a value.


    print t('Welcome, @user', $values); where Drupal will check for the placeholder begins with @ , then before it utilize to insert the value, Drupal sanitizes the value using its internal check_plain() function


    for more detail please visit https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: