Tag: angular translate

使用angular度转换处理API错误的最佳做法

我有一个API <> SPA架构。 但我不知道在哪里翻译,特别是当发送错误。 我宁愿只在我的angular度应用程序翻译文本(i18n等)。 API只能发送英文文本。 但我不知道如何 想象一下这样的错误消息:(nodejs + restify) server.get('/api/', function (req, res, next) { return next(new server.errors.UnauthorizedError('You are not authorized')); }); 这将发送一个401与json的身体。 如果API只会说英文,那么我怎样才能在SPA上翻译呢? 我怎么能把这个翻译方法之一: <span>{{message | translate}}</span> 要么 <span>{{lang.message}}</span> 当然,我使用Angular的$ translateProvider,并且在其中有一个定位文件。 有没有其他的方式发送语言键? 喜欢这个: server.get('/api/', function (req, res, next) { return next(new server.errors.UnauthorizedError('NOT_AUTHORIZED_ERROR')); }); 有了这个我可以有一个locate-en.json文件,如: { errors: { NOT_AUTHORIZED_ERROR: "You are not authorized" } […]