Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created July 12, 2019 20:24
Show Gist options
  • Save rpayanm/b061fb585c78f167c4b46a1a3c0fd18b to your computer and use it in GitHub Desktop.
Save rpayanm/b061fb585c78f167c4b46a1a3c0fd18b to your computer and use it in GitHub Desktop.

Make Strings Translatable

Placeholders

@variable

Use this style of placeholder for most use-cases. Special characters in the text will be converted to HTML entities.

t('Hello @name, welcome back!', array('@name' => $user->getDisplayName()));

Output example:

Hello Dries, welcome back!

%variable

Use this style of placeholder to pass text through drupal_placeholder() which will result in the text being HTML escaped, and then wrapped with <em> tags.

t('The file was saved to %path.', array('%path' => $path_to_file));

Output example:

The file was saved to <em class="placeholder">sites/default/files/myfile.txt</em>.

:variable

Use this style of placeholder when substituting the value of an href attribute. Values will be HTML escaped and filtered for dangerous protocols.

t('Hello <a href=":url">@name</a>', array(':url' => 'http://example.com', '@name' => $name));

Output example:

Hello <a href="http://example.com">Dries</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment