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?
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.
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.
HTML Formatting Elements <b> - Bold text. <strong> - Important text. <i> - Italic text.
Type the keyboard shortcut: CTRL+B.
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! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With