gpt4 book ai didi

javascript - 使用 React 将 iso 语言代码的值转换为语言

转载 作者:行者123 更新时间:2023-12-02 21:14:50 24 4
gpt4 key购买 nike

我正在尝试如何转换现有的数据模拟,其中我有 ISO 代码,我想将其转换为语言名称。

我正在使用 => https://github.com/pubcore/iso-language-codes (自述文件实际上有 2 个小错误,该示例不是从 iso-language-codes 导入,并且 code = iso639_2T['fra'] 应该是 code = by639_2T ['fra'] )

这是我的数据模拟:

export const dataForSubtitlesMenu = [
{ value: 'Lingue Audio', title: true, id:1},
{ value: 'ita', id: 2},
{ value: 'eng', id: 3},
{ value: 'fra', id: 4},
{ value: 'ben', id: 5},
{ value: 'gla', id: 6},
{ value: 'ind', id: 8},
{ value: 'nor', id: 9},
{ value: 'rus', id: 10},
{ value: 'slv', id: 11},
]

这是我的app.js

<Dropdown title="Seleziona lingua e sottotitoli" items={dataForSubtitlesMenu}/>

Dropdown.js 中我确实喜欢这个

<ul className="dd-list">
{items.map((item, i) => (
<ListItem
item={item}
/>
))}
</ul>

没有示例和清晰的演示,我如何使用此模块iso-languages-code将我的值转换为语言代码?有没有其他更好的节点可以使用我现有的数据模拟来实现此目的?

最佳答案

您似乎只想为该库中的每种语言创建一个条目?

如果是这样,默认导出只是所有数据的数组。所以你应该能够:

import codes from 'iso-country-codes'

export const dataForSubtitlesMenu = [
// Add the prompt item
{ value: 'Lingue Audio', title: true, id:1},

// Fill the rest of the array with an item for every language.
...codes.map((lang, i) => ({
value: lang.iso639_2T,
id: i + 2, // i starts at 0, id 1 is the prompt.
})
]

关于javascript - 使用 React 将 iso 语言代码的值转换为语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60998935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com