在react-intl-universal 中,你可以使用 intl.get 方法来获取翻译后的文本,并且可以通过在翻译字符串中嵌入变量来实现动态内容的插入。以下是如何在翻译文本中添加变量的步骤和示例代码: 定义翻译文件: 在翻译文件中,你可以使用占位符来表示需要插入的变量。例如,假设你有一个英文翻译文件 en.json,内容如下: json { "
{this.state.intlDone&& {intl.get("intl.hello")} {intl.getHTML('content')} this.changeLanguage()}> {intl.getHTML('intl.changeLang')} } ) } } export default IntlOldLearn 封装高阶组件 可复用的多语高阶组件 import React from 'react'; import intl from 'react-intl-universal' export...
import intl from 'react-intl-universal' import { withRouter } from "react-router-dom"; class App extends Component { constructor(props) { super(props) this.state = { initDone: false } } render() { return ( {intl.get('login.username')} {intl.get('editor.item.name')} EN/中 );...
intl.get('page1.hello');// "Hello world"intl.get('page2.hello');// "Hello react-intl-universal!" Thanks@elgalesmanafor the contribution. Assets2 Tetita reacted with heart emoji ️ 1 person reacted 15 Aug 05:44 cwtuan
Currency Example: Code {intl.get('SALE_PRICE', { price })} Result 售价¥123,456.78 Message Not in Component Example: Code {util.getMessage()} Result react-intl-universal可以在非React Component的js文件进行国际化 react-intl-universal-extract:...
项目要实现一个中英文切换,react配合antd使用react-intl-universal出现报错:GET https://g.alicdn.com/react-intl-universal/locale-data/1.0.0/en.js net::ERR_NAME_RESOLUTION_FAILEDUncaught (in promise) E...
Get Started Install npm install react-intl-universal --save Initialize In the following example, we initializeintlwith app locale data (locales) and determine which locale is used dynamically (currentLocale). Then useintl.get(...)to get the internationalized message. That's all. Pretty simple!
If the message contains variables the{variable_name}is substituted directly into the string. In the example below, there are two variables{name}and{where}, the second argument representing the variables ingetmethod are substituted into the string. ...
import React, { Component } from 'react'; import intl from 'react-intl-universal' import { withRouter } from "react-router-dom"; class App extends Component { constructor(props) { super(props) this.state = { initDone: false } } render() { return ( {intl.get('login.username')} {...
Get Started Install npm install react-intl-universal --save Basic Example In the following example, we initializeintlwith app locale data (locales) and determine which locale is used dynamically (currentLocale). Then useintl.get(...)to get the internationalized message. That's all. Pretty simpl...