简体   繁体   中英

Rails Localization: Is there any disadvantage in arranging i18n yml text in a flat non-nested way?

I always see nested yml content which I think wastes space and text.

Is there any disadvantage in arranging translations from this way:

en:
  errors:
    template:
      body: "Body error message"
        header:
          one:    "1 error "
          other:  "%{count} errors"

into this way:

en:
  errors:
    body: "Body error message"
    one: "1 error "
    other: "%{count} errors"

or even this:

en:
  error_body: "Body error message"
  error_one: "1 error "
  error_other: "%{count} errors"

What you think as taking space is just the way it is displayed, and does not necessarily reflect the amount of information. Particularly, keep in mind that a newline takes up one line when displayed, but is just a single character. And for example, your third example may look like taking less lines, but includes repetition of the word error , and in terms of number of characters, it takes up more characters than the second one, and is in fact waste of information.

As with the second example compared to the first one, the first one is better in terms of modularity. If you had several templates for displaying an error message, then the first format will distinguish that, whereas your second format will mix them up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM