简体   繁体   English

覆盖I18n中的嵌套翻译

[英]Overwriting nested translations in I18n

Say I have the following en.yml: 说我有以下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? 什么是覆盖字的最好办法breaks ,而不必复制粘贴其他所有的翻译?

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: wheelengine等所有其他翻译都消失了some_other_category因为我要覆盖car:所有翻译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 资料来源: https : //gist.github.com/bowsersenior/979804

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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