Skip to content

Commit

Permalink
Add i18n HAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
hickeyma committed Oct 24, 2016
1 parent ddfc6a7 commit 21255b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core_plugins/i18n/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as i18n from './server/i18n/i18n';
import route from './server/route';

export default function (kibana) {
return new kibana.Plugin({
Expand All @@ -11,10 +12,15 @@ export default function (kibana) {
},

init(server, options) {

// Expose i18n module APIs
server.expose('getTranslationsForLocale', i18n.getTranslationsForLocale);
server.expose('getTranslationsForLocales', i18n.getTranslationsForLocales);
server.expose('getRegisteredTranslationLocales', i18n.getRegisteredTranslationLocales);
server.expose('registerTranslations', i18n.registerTranslations);

// Add HAPI to get i18n translations
route(server);
}
});
};
25 changes: 25 additions & 0 deletions src/core_plugins/i18n/server/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Boom from 'boom';

import langParser from 'accept-language-parser';
import * as UiI18n from '../../../ui/ui_i18n';

const DEFAULT_LOCALE = 'en';

export default function (server) {

server.route({
path: '/api/i18n',
method: 'GET',
handler(req, reply) {
const acceptLanguageStr = req.headers['accept-language'];
const acceptLanguages = langParser.parse(acceptLanguageStr);

return UiI18n.getTranslations(acceptLanguages, DEFAULT_LOCALE, server).then(function (translations) {
reply(translations);
}).catch(function (e) {
reply(Boom.internal(e));
});
}
});
};

0 comments on commit 21255b2

Please sign in to comment.