mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: i18n middleware
feat: i18n configuration. feat: i18n with tenancy.
This commit is contained in:
@@ -4,6 +4,7 @@ import agendaFactory from '@/loaders/agenda';
|
||||
import SmsClientLoader from '@/loaders/smsClient';
|
||||
import mailInstance from '@/loaders/mail';
|
||||
import dbManagerFactory from '@/loaders/dbManager';
|
||||
import i18n from '@/loaders/i18n';
|
||||
|
||||
export default ({ mongoConnection, knex }) => {
|
||||
try {
|
||||
@@ -29,6 +30,9 @@ export default ({ mongoConnection, knex }) => {
|
||||
Container.set('agenda', agendaInstance);
|
||||
LoggerInstance.info('Agenda has been injected into container');
|
||||
|
||||
Container.set('i18n', i18n);
|
||||
LoggerInstance.info('i18n has been injected into container');
|
||||
|
||||
return { agenda: agendaInstance };
|
||||
} catch (e) {
|
||||
LoggerInstance.error('Error on dependency injector loader: %o', e);
|
||||
|
||||
@@ -2,20 +2,42 @@ import express from 'express';
|
||||
import helmet from 'helmet';
|
||||
import boom from 'express-boom';
|
||||
import errorHandler from 'errorhandler';
|
||||
import i18n from 'i18n';
|
||||
import fileUpload from 'express-fileupload';
|
||||
import i18n from 'i18n';
|
||||
import routes from '@/http';
|
||||
import config from '@/../config/config';
|
||||
|
||||
export default ({ app }) => {
|
||||
// Express configuration.
|
||||
app.set('port', 3000);
|
||||
|
||||
// Helmet helps you secure your Express apps by setting various HTTP headers.
|
||||
app.use(helmet());
|
||||
|
||||
// Allow to full error stack traces and internal details
|
||||
app.use(errorHandler());
|
||||
|
||||
// Boom response objects.
|
||||
app.use(boom());
|
||||
|
||||
// Parses both json and urlencoded.
|
||||
app.use(express.json());
|
||||
|
||||
// Handle multi-media requests.
|
||||
app.use(fileUpload({
|
||||
createParentPath: true,
|
||||
}));
|
||||
routes(app);
|
||||
|
||||
// Initialize i18n node.
|
||||
app.use(i18n.init)
|
||||
|
||||
// Prefix all application routes.
|
||||
app.use(config.api.prefix, routes());
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use((req, res, next) => {
|
||||
const err = new Error('Not Found');
|
||||
err['status'] = 404;
|
||||
next(err);
|
||||
})
|
||||
};
|
||||
9
server/src/loaders/i18n.ts
Normal file
9
server/src/loaders/i18n.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import i18n from 'i18n';
|
||||
import path from 'path';
|
||||
|
||||
export default () => i18n.configure({
|
||||
locales: ['en', 'ar'],
|
||||
register: global,
|
||||
directory: path.join(global.rootPath, 'src/locales'),
|
||||
updateFiles: false
|
||||
})
|
||||
@@ -5,6 +5,7 @@ import expressLoader from '@/loaders/express';
|
||||
import databaseLoader from '@/database/knex';
|
||||
import dependencyInjectorLoader from '@/loaders/dependencyInjector';
|
||||
import objectionLoader from '@/database/objection';
|
||||
import i18nConfig from '@/loaders/i18n';
|
||||
|
||||
// We have to import at least all the events once so they can be triggered
|
||||
import '@/loaders/events';
|
||||
@@ -29,4 +30,7 @@ export default async ({ expressApp }) => {
|
||||
|
||||
expressLoader({ app: expressApp });
|
||||
Logger.info('Express loaded');
|
||||
|
||||
i18nConfig();
|
||||
Logger.info('I18n node configured.');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user