简体   繁体   English

在反应网站中存储多语言文本的最佳实践是什么

[英]What is the best practice to store multi language text in a react web site

I am building a react website, and It has multiple localizations.我正在构建一个 React 网站,它有多个本地化。 What is the best practice to store ui texts for different languages?存储不同语言的 ui 文本的最佳做法是什么? I am currently considering the two我目前正在考虑这两个

  • Store text in ui code, as an object variable or array, for multiple languages将文本存储在 ui 代码中,作为对象变量或数组,适用于多种语言
    This way, I am fearing it could scatter the text in many files and could make the the site load slow since all the text is included with the code这样,我担心它会将文本分散在许多文件中,并且可能使站点加载缓慢,因为所有文本都包含在代码中
  • Storing in a static JSON file in a server directory存储在服务器目录中的静态 JSON 文件中
    This way I am fearing with many components requesting their texts, it would appear bad with text loading slowly on every page.通过这种方式,我担心许多组件会请求它们的文本,如果每个页面上的文本加载缓慢,这会显得很糟糕。 I might make it fetch all once for all component, but that would seriously hinder the modularity.我可能会为所有组件一次性获取所有内容,但这会严重阻碍模块化。

What is the best practice to implement text storage for multiple localization react app?为多个本地化反应应用程序实现文本存储的最佳实践是什么?

First, you need to use npm packages i18next react-i18next首先需要使用npm包i18next react-i18next

Here is good tutorial how to do it这是如何做到这一点的好教程

https://www.mindbowser.com/adding-multi-language-support-using-reactjs/ https://www.mindbowser.com/adding-multi-language-support-using-reactjs/

You should save as local Json, no need for static translation to be served from server.您应该保存为本地 Json,不需要从服务器提供静态翻译。

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

相关问题 API设计-存储诸如HTML之类的富文本的最佳实践是什么 - API Design - What are the best practice to store Rich text like HTML 在多语言网站上设置默认语言 - Set default language in multi language web site 在 React 中制作可选的可编辑文本字段的最佳做法是什么? - What's the best practice for making an optionally editable text field in react? 在本地为Web存储数据的最佳实践 - Best practice to store data locally for web 由Flux Store控制的React Form(最佳实践?) - React Form controlled by a Flux Store (Best practice?) 在不使用经典的 html 表单的情况下,在 web 应用程序中存储隐藏值的最佳做法是什么? - What is the best practice to store hidden values in web apps, without using the classic html form? 什么是最佳实践导航反应原生 - what's the best practice navigation react native websocket 在反应中重新连接的最佳实践是什么? - What is best practice to websocket reconnect in react? 在 javascript 中编写 object 并做出反应的最佳实践是什么 - What is best practice for writing object in javascript and react 使用 react 调用 API 的最佳实践是什么 - What's the best practice to call API with react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM