【问题标题】:How to use i18n translations as a key for an object如何使用 i18n 翻译作为对象的键
【发布时间】:2021-11-09 01:53:55
【问题描述】:

我正在使用 react js 。我需要动态地使用翻译值作为对象的键。我怎样才能做到这一点。下面展示了我尝试过的方式,但我确信这不是正确的方式。任何人都可以为此目的建议我一个更好的方法


    const initialValues = {
                i18n.t("name.drawing"): {
                items: [],
                startDate: null,
                endDate: null,
                
            },
            i18n.t("name.dancing"): {
                items: [],
                startDate: null,
                endDate: null,
            },
        };

【问题讨论】:

    标签: javascript reactjs angularjs i18next


    【解决方案1】:

    将键括在括号中 -

        const initialValues = {
                    [i18n.t("name.drawing")]: {
                    items: [],
                    startDate: null,
                    endDate: null,
                    
                },
                [i18n.t("name.dancing")]: {
                    items: [],
                    startDate: null,
                    endDate: null,
                },
            };
    

    【讨论】:

      猜你喜欢
      • 2011-05-03
      • 1970-01-01
      • 2018-01-25
      • 2021-01-20
      • 2019-01-28
      • 2011-10-11
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多