Refactoring Ruby on Rails i18n YAML files using dictionaries

后端 未结 4 1551
长发绾君心
长发绾君心 2020-12-08 14:55

This StackOverflow question gave me food for thought on what is a good structure for Rails i18n files, so I thought I\'d share another structure for refactoring Rails i18n y

4条回答
  •  孤城傲影
    2020-12-08 15:18

    Improving of refactiring YAML files, especially for those who have many models:

    ru:
      dictionary:
        name: &name "Имя"
        title_ru: &title_ru "Заголовок (ru)"
        title_en: &title_en "Заголовок (en)"
        content_ru: &content_ru "Содержание (ru)"
        content_en: &content_en "Содержание (en)"
        role: &role "Роль"
        created_at: &created_at "Создано в"
        updated_at: &updated_at "Обновлено в"
        published: &published "Опубликовано"
    
        nomination: &nomination
          name: *name
          title_ru: *title_ru
          title_en: *title_en
    
        post: &post
          content_ru: *content_ru
          content_en: *content_en
          published: *published
    
        dates: &dates
          created_at: *created_at
          updated_at: *updated_at
    
      activerecord:
        attributes:
          article:
            <<: *nomination
            <<: *post
            <<: *dates
    
          user:
            <<: *dates
            role: *role
            email: "Электропочта"
    

    Userful link

提交回复
热议问题