我们如何在 AWS Amplify 中以多级结构定义翻译?

How can we define translations in AWS Amplify in a multi-level structure?

我想在 AWS Amplify 中以结构更好的方式定义我的翻译字符串。类似于此:

export const strings = {
  en: {
    home: {
        icon: "Home",
    },
    profile: {
        fname: "Given name"
    }
  },
  de: {
    home: {
        icon: "Start",
    },
    profile: {
        fname: "Vorname"
    }
  },
};

然而,这种结构对于扩增是不可识别的。我的意思是我无法获得像 I18n.get('home.icon');

这样的字符串

问题是,有什么办法可以这样组织字符串吗?

我知道可以将字符串拆分到不同的文件中:

import { mergeDeepRight } from 'ramda';
import { strings as todosStrings } from './todos/strings';
import { strings as userStrings } from './user/strings';
I18n.putVocabularies(mergeDeepRight(todosStrings, userStrings));

但似乎我仍然必须确保变量名称在所有文件中都是唯一的!

另一种可能是使用I18n.get('home').icon但它不符合i18n的后备机制!

看起来很直观,但是,通过与其他 i18n 库的比较,我得出了这个结论,将键定义为 x.y.z:

export const strings = {
  en: {
    "header.icon.home": "Home"
  },
  de: {
    "header.icon.home": "Start"
  },
};

不过,如果有人有任何更好的体验,我会很高兴听到。