Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling text in localization files — bold, italic, etc

What techniques/methods are there for dealing with emphasized or stylized text in localized strings?

For example, how might a brief title such as the one below (4–8 words) be italicized?

Welcome to the Machine, John.

Is there a more efficient way than 3 lookups, plus a variable to define the structure?

like image 212
coreyward Avatar asked Jan 13 '16 22:01

coreyward


People also ask

How do you Format text italics and bold?

To make text bold, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and press B on the keyboard. To make text italic, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and then press the I on the keyboard.

What is bold italic used for?

They're intended for emphasis and if everything (i.e.: a whole paragraph) is all caps/bold/italic, nothing is emphasized. Italicization is used for gentle emphasis, bold is used for heavier emphasis. All caps are another alternative means of emphasis. None of these should be used on more than a few words together.

Which tag is used to italic and bold in text?

HTML Formatting Elements <b> - Bold text. <strong> - Important text. <i> - Italic text.

How do you apply the bold style to text?

Type the keyboard shortcut: CTRL+B.


1 Answers

Check out documentation it says:

Third, it'll mark the translation as safe HTML if the key has the suffix “_html” or the last element of the key is the word “html”. For example, calling translate(“footer_html”) or translate(“footer.html”) will return a safe HTML string that won't be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that you know what kind of output to expect when you call translate in a template.

So you need to append suffix _html to your key and now you can use html in your locales.

For example this is your locale file:

en:
  welcome:
    html: '<b>Hello!</b> This is first way to style your locales!'
  welcome_html: '<b>Hi again!</b> This is second way to style your locales!'

Now just set I18n.t 'en.welcome.html' or I18n.t 'en.welcome_html' in your views. That's all! :)

like image 84
axvm Avatar answered Nov 26 '22 07:11

axvm