- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用标准 <FormattedMessage../>
直接在 comp 外部调用 formatMessage() API组件。
const locale = 'en';
const messages= defineMessages({
greeting: {
id: 'app.greeting',
message:"some message",
defaultMessage: 'Hello,all',
description: 'Greeting to welcome the user to the app',
}
});
const { intl } = new IntlProvider({locale, messages}).getChildContext();
export function someFunc(key, values) {
return intl.formatMessage({id:'greeting'});
}
上面是本地定义的静态消息,但是我有一个翻译文件 en.json 和 ja.json 全局存储,我想从中加载消息。我怎样才能使用defineMessages做到这一点,这样当我调用formatMessage()时,我应该能够根据所选的区域设置从resp文件中看到消息......想法赞赏!谢谢!
最佳答案
我不知道您的 .json
文件的格式,但您可以重新格式化它们(如果需要),以便其中的每个键至少具有 id
和 defaultMessage
( details ) 并传递给 defineMessages()
函数。
import enMessages from 'path/to/en.json'
import jaMessages from 'path/to/ja.json'
const localeMessages = locale === 'en' ? enMessages : jaMessages
const messages= defineMessages(localeMessages);
...
const { intl } = new IntlProvider({locale, messages}).getChildContext();
intl.formatMessage({id:'greeting'});
关于reactjs - 如何调用 formatMessage() 从 .json 文件加载消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44013853/
当传递给 FormatMessage 的参数太长时,我遇到了问题。 void testMessage(UINT id, ...) { va_list argList; va_start
如何从父组件获取 intl.formatMessage ?我用injectIntl包装了父组件,并希望将intl.formatMessage发送到子组件。有人可以帮我吗?谢谢! 父组件 impor
CString ErrorMessageFromErrorCode(DWORD errorCode){ void* pMsgBuf = NULL; ::FormatMessage(
是否可以翻译system error codes特定语言? 我只能通过MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)至 FormatMessage .否则,函
当一个参数值用于多个时,FORMATMESSAGE 函数返回 NULL消息字符串。 DECLARE @myvar VARCHAR(10) = 100 SELECT FORMATMESSAGE ('Fi
我用的是CodeBlocks和Mingw:g++版本是4.7.1 例子来自 MSDN (请参阅最后一个示例,就在“要求”部分之前): // Formats a message string using
我正在尝试使用 react-intl为我的应用添加本地化。像这样 但我需要一个字符串,所以我尝试了这个 const title = this.props.intl.formatMessage({
我使用react-intl与 en和fr ,我的 React 应用程序包含在 中 这样,例如当lang是 en ,全部intl.formatMessage调用结果为英文文本。 我想要实现的是我想要
我不确定我的实现是否存在根本性问题,或者 Windows API 中是否存在关于格式化系统错误消息的错误。 我有一个用于 FormatMessage 函数的 Windows API 包装器方法。我的实
当我执行以下代码片段时,它失败并显示错误代码 317。如何解决问题?我们正在为项目使用 Unicode 字符集 char* pszMessgeBuffer = NULL; FormatMess
我正在尝试学习一些 WinAPI 知识,并且正在使用 RegOpenKeyEx 函数。我有这段代码: LPCTSTR subKey; subKey = TEXT("WinSide"); HKEY hK
我需要使用 FormatMessage()对于一个项目,但我不喜欢它可怕的界面。有谁知道在允许替换参数的同时整理它的外观? 我刚刚阅读了 second part of the FastFormat i
没有: MFC ATL 如何使用 FormatMessage()获取 HRESULT 的错误文本? HRESULT hresult = application.CreateInstance("Exc
我正在尝试使用标准 直接在 comp 外部调用 formatMessage() API组件。 const locale = 'en'; const messages= defineMessages(
我正在尝试使用 react-intl 进行语言翻译。当我使用这个时,它运行完美。但是当我将以下代码与 intl.formatMessage() 一起使用时,它不起作用并抛出一些错误。我不知道这有什么问
我有一个如下所示的函数: void test() { char lpBuffer[MAX_PATH]; LPVOID pv = NULL; va_list Environmen
我正在调用 SetupCopyOEMInf 来复制设备驱动程序的 .inf 文件(MSFT 文档说:“SetupAPI 继续用于 installing device drivers”)。 调用返回 f
这个问题在这里已经有了答案: Javascript object bracket notation ({ Navigation } =) on left side of assign (5 个答案)
我正在运行它来测试 FormatMessage : LPVOID lpMsgBuf; errCode=12163; FormatMessage( FORMAT_MESSAGE_ALLOCATE
我只是想用这个简单的代码获取最后一个错误的文本: #include #include #include int main(){ char err[256]; memset(err
我是一名优秀的程序员,十分优秀!