Internationalization 流星误差国际化
我正在尝试通过实现国际化,到目前为止效果很好 问题是我还使用帐户密码,尤其是密码 登录错误时,回调有一个错误对象,基本上如下所示:Internationalization 流星误差国际化,internationalization,coffeescript,meteor,Internationalization,Coffeescript,Meteor,我正在尝试通过实现国际化,到目前为止效果很好 问题是我还使用帐户密码,尤其是密码 登录错误时,回调有一个错误对象,基本上如下所示: { details: undefined, error: 403, errorType: "Meteor.Error", message: "User not found [403]", reason: "User not found" } i18n.map 'fr_FR', login: signin: 'S\
{
details: undefined,
error: 403,
errorType: "Meteor.Error",
message: "User not found [403]",
reason: "User not found"
}
i18n.map 'fr_FR',
login:
signin: 'S\'authentifier'
errors:
403: 'L\'utilisateur n\'existe pas'
我认为错误代码是唯一的,并使用了如下i18n配置文件:
{
details: undefined,
error: 403,
errorType: "Meteor.Error",
message: "User not found [403]",
reason: "User not found"
}
i18n.map 'fr_FR',
login:
signin: 'S\'authentifier'
errors:
403: 'L\'utilisateur n\'existe pas'
所以我可以这样称呼它:
Session.set "error", i18n("errors." + err.error)
但实际上,无论是什么错误、用户未找到或密码不正确,错误代码都不是唯一的:
{
details: undefined,
error: 403,
errorType: "Meteor.Error",
message: "Incorrect password [403]",
reason: "Incorrect password"
}
因为我不认为检查一个字符串值真的是一致的,我如何区分两者?
我如何使用meteor内置登录实现国际化?
403
这里不是特定错误的meteor编号,而是一个。相同的代码可能由不同的错误引起
由于您得到的错误对象之间的唯一区别是reason
和message
,因此您需要使用其中一个来设置国际化代码。它们在Meteor版本之间不会有太大的变化,所以您应该可以使用此解决方案
i18n.map 'fr_FR',
login:
signin: 'S\'authentifier'
errors:
403:
'Incorrect password': 'Le password est incorrectu'
'User not found': 'L\'utilisateur n\'existe pas'
啊,别担心,
登录
、登录
、错误
和403
在内部也表示为字符串,所以在这种解决方案中没有任何不一致之处 我觉得用简单的字符串句子作为键是很奇怪的,但它的效果和预期的一样,而且你关于一致性的论点似乎也很有道理。