简体   繁体   中英

Overwriting nested translations in I18n

Say I have the following en.yml:

default_category: &default
  car:
    wheel: Wheel
    engine: Engine
    ...
    ...
    breaks: Breaks

some_other_category:
  <<: *default

What would be the best way to overwrite the word breaks without having to copy paste all the other translations?

Tried so far:

If you do this:

default_category: &default
  car:
    wheel: Wheel
    engine: Engine
    ...
    ...
    breaks: Breaks

some_other_category:
  <<: *default
  car:
    breaks: Super Breaks

All the other translations like wheel and engine are gone for some_other_category because I'am overwriting all translations for car:

If you do this:

default_category: &default
  car:
    wheel: Wheel
    engine: Engine
    ...
    ...
    breaks: Breaks

some_other_category:
  <<: *default
  car:
    wheel: Wheel
    engine: Engine
    ...
    ...
    breaks: Super Breaks

There's duplicate code due to copy/pasting.

The option to move the default pointer to the car is not really an option in my scenario.

Is there a nicer way to do this?

Fixed it myself, the solution is to add an extra pointer to car, not move the pointer.

default_category: &default
  car: &default_car
    wheel: Wheel
    engine: Engine
    ...
    ...
    breaks: Breaks

some_other_category:
  <<: *default
  car:
    <<: *default_car
    breaks: Super Breaks

Source: https://gist.github.com/bowsersenior/979804

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