javascript - 如何使用 react-native-localize 本地化基于数组的文本
问题描述
我正在使用 react-native-localize 在我的项目中设置本地化,使用普通字符串我只使用像这样的普通 i18n 助手,简单明了。
{I18n.t("filter")}
但是对于基于数组的数据,我该怎么做,例如我有一个 Carousel,它从这样的数据数组中获取它的项目:
const [ bookSliders, setBookSliders] = useState([
{ image:'/img/misc/sin-favoritos.jpg', id:2,title:'¡Salva una mesa vacia!',body:'Reservando una mesa con descuento durante las horas vacias ayudas a los restaurantes a conseguir la máxima ocupación en estos tiempos complicados.' },
{ image:'/img/misc/sin-pack.jpg', id:1, title:'Reserva desde la app',body:'Realiza tu pedido y paga facilmente desde la app , recuerda presentarte en el establecimiento entre las horas acordada.' },
<Carousel firstItem={0} onSnapToItem={slideIndex => { console.log(slideIndex); setActiveSlide(slideIndex) }} enableSnap data={bookSliders}
renderItem={({ item }) =>
<View style={{ backgroundColor:'white', width:370, borderWidth:0,height:340, flexDirection:'column', alignItems:'center', justifyContent:'center' }}>
<Image style={{ width:140,height:140,marginBottom:10}} resizeMode="cover" source={{uri: env.BASE_URL+item.image }}/>
{/*<Image style={{ width:140, height:140,marginBottom:10 }} resizeMode="contain" source={require('@assets/images/sandia.png')}/>*/}
<Text style={{ fontSize:18, color:'black',marginBottom:10,fontFamily:'AirbnbCerealMedium',textAlign:'center' }}>{ item.title }</Text>
<Text style={{ width:'85%',fontSize:16, color:'rgb(125,125,125)',marginBottom:5 ,textAlign:'center',fontFamily:'AirbnbCerealBook'}}>{ item.body }</Text>
</View>}
sliderHeight={125} itemHeight={340} itemWidth={370} vertical={false} sliderWidth={340}/>
请注意我如何使用 {item.title} 和 {item.body} 来显示相应的活动幻灯片,但是如何使用 i18n 翻译助手显示正确的字符串?
我的本地化 json 文件如下所示:
export default {
hello: "Hola",
filter:"Filtros",
map:"Mapa",
sort:"Ordenar",
list:"Lista",
};
解决方案
推荐阅读
- ruby-on-rails - 如何更改mapbox中popupwindow的css?
- label - Mapbox Studio:从上传的图层添加标签
- java - 在 IntelliJ 社区中设置 Apache Derby 数据库
- ruby-on-rails - 如何在 Nginx 和 Unicorn for Rails 应用程序上配置 SSL?
- javascript - 导出变量以在 JavaScript 中的其他模块中使用
- flutter - 没有 AutoId 的 Firestore 嵌套集合!如何用代码创建?
- python - PyYAML 对象返回字典
- java - 无法将字符串转换为 json 数组并解析
- php - Laravel 编辑用户数据但显示输入电子邮件错误。电子邮件已被占用
- python - 无法通过删除 python 中的垃圾值将 csv 转换为数组 json?