I18n questions · Localization files
For a line break, put \n in a double-quoted value or use a block scalar. For everything else there is one rule: if a value contains or starts with a character that means something in YAML, quote it.
en:
address: "Line one\nLine two"
terms: |
First paragraph.
Second paragraph.
intro: >
A long sentence written on
several lines that becomes
one line with spaces.
| keeps every line break. > turns a single line break into a space and keeps an empty line as a paragraph break. Both end with one trailing newline; write |- or >- to drop it. Only double quotes understand backslash escapes such as \n, \t, \" and \\. Single quotes take everything literally, and their only escape is a doubled quote for an apostrophe: 'It''s ready'. The YAML 1.2 spec has the full list of escapes.
Values that must be quoted:
# preceded by a space starts a comment, so Item #1 of 3 is stored as Item. Write "Item #1 of 3".error: Error: file not found needs quotes.* (alias), & (anchor), ! (tag), % (directive), [ or { (flow collection), | or > (block scalar), a quote, or -, ? and : followed by a space. @ and the backtick are reserved and cause a parse error at the start of a value. So *Required field and [beta] go in quotes.yes, no, y, n, on, off, true and false (in any capitalization) become booleans, and ~, null or an empty value become nil. The classic case is confirm: Yes turning into true; write confirm: "Yes". Unquoted numbers are converted too, so "1.10" as a version label needs quotes or it becomes 1.1.When in doubt, double-quote the value. Quoting never changes the meaning of a string; it only removes the ambiguity.
Two Rails details. A \n does nothing in HTML; render such a string with simple_format, which turns single newlines into <br /> and blank lines into <p> tags, or put <br> into a key ending in _html. And indentation must be spaces, never tabs; a block scalar's lines must be indented deeper than its key.
To check a whole file quickly, paste it into the YAML validator. The layout of Rails locale files is described at Rails YAML file.
Published Oct 9, 2026 · Markdown version