mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: localization invoice, estimate and receipt pdf templates.
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { Container } from 'typedi';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import i18n from 'i18n';
|
||||
import HasTenancyService from 'services/Tenancy/TenancyService';
|
||||
import { injectI18nUtils } from './TenantDependencyInjection';
|
||||
|
||||
/**
|
||||
* I18n from organization settings.
|
||||
*/
|
||||
export default (req: Request, res: Response, next: NextFunction) => {
|
||||
const Logger = Container.get('logger');
|
||||
const { settings } = req;
|
||||
const { settings, tenantId } = req;
|
||||
|
||||
if (!req.user) {
|
||||
throw new Error('Should load this middleware after `JWTAuth`.');
|
||||
@@ -16,9 +18,8 @@ export default (req: Request, res: Response, next: NextFunction) => {
|
||||
throw new Error('Should load this middleware after `SettingsMiddleware`.');
|
||||
}
|
||||
// Get the organization language from settings.
|
||||
const language = settings.get({
|
||||
group: 'organization', key: 'language',
|
||||
});
|
||||
const language = settings.get({ group: 'organization', key: 'language' });
|
||||
|
||||
if (language) {
|
||||
i18n.setLocale(req, language);
|
||||
}
|
||||
@@ -26,5 +27,10 @@ export default (req: Request, res: Response, next: NextFunction) => {
|
||||
language,
|
||||
user: req.user,
|
||||
});
|
||||
const tenantServices = Container.get(HasTenancyService);
|
||||
const tenantContainer = tenantServices.tenantContainer(tenantId);
|
||||
|
||||
tenantContainer.set('i18n', injectI18nUtils(req));
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
@@ -11,15 +11,11 @@ export default async (req: Request, res: Response, next: NextFunction) => {
|
||||
if (tenantContainer && !tenantContainer.has('settings')) {
|
||||
const { settingRepository } = tenantContainer.get('repositories');
|
||||
|
||||
Logger.info('[settings_middleware] initialize settings store.');
|
||||
|
||||
const settings = new SettingsStore(settingRepository);
|
||||
tenantContainer.set('settings', settings);
|
||||
}
|
||||
Logger.info('[settings_middleware] get settings instance from container.');
|
||||
const settings = tenantContainer.get('settings');
|
||||
|
||||
Logger.info('[settings_middleware] load settings from storage or cache.');
|
||||
await settings.load();
|
||||
|
||||
req.settings = settings;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ITenant } from 'interfaces';
|
||||
import { Request } from 'express';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import TenantsManagerService from 'services/Tenancy/TenantsManager';
|
||||
import rtlDetect from 'rtl-detect';
|
||||
|
||||
export default (req: Request, tenant: ITenant) => {
|
||||
const { id: tenantId, organizationId } = tenant;
|
||||
@@ -20,7 +21,7 @@ export default (req: Request, tenant: ITenant) => {
|
||||
|
||||
const tenantContainer = tenantServices.tenantContainer(tenantId);
|
||||
|
||||
tenantContainer.set('i18n', { __: req.__ });
|
||||
tenantContainer.set('i18n', injectI18nUtils(req));
|
||||
|
||||
req.knex = knexInstance;
|
||||
req.organizationId = organizationId;
|
||||
@@ -29,4 +30,18 @@ export default (req: Request, tenant: ITenant) => {
|
||||
req.models = models;
|
||||
req.repositories = repositories;
|
||||
req.cache = cacheInstance;
|
||||
}
|
||||
|
||||
|
||||
export const injectI18nUtils =(req) => {
|
||||
const locale = req.getLocale();
|
||||
const direction = rtlDetect.getLangDir(locale);
|
||||
|
||||
return {
|
||||
locale,
|
||||
__: req.__,
|
||||
direction,
|
||||
isRtl: direction === 'rtl',
|
||||
isLtr: direction === 'ltr',
|
||||
}
|
||||
}
|
||||
@@ -160,5 +160,32 @@
|
||||
"Liabilities and Equity": "التزامات وحقوق الملكية",
|
||||
"Closing balance": "الرصيد الختامي",
|
||||
"Opening balance": "الرصيد الفتاحي",
|
||||
"Total {{accountName}}": "إجمالي {{accountName}}"
|
||||
"Total {{accountName}}": "إجمالي {{accountName}}",
|
||||
"invoice.paper.invoice": "فاتورة",
|
||||
"invoice.paper.due_amount": "القيمة المستحقة",
|
||||
"invoice.paper.billed_to": "فاتورة إلي",
|
||||
"invoice.paper.invoice_date": "تاريخ الفاتورة",
|
||||
"invoice.paper.invoice_number": "رقم الفاتورة",
|
||||
"invoice.paper.due_date": "تاريخ الاستحقاق",
|
||||
"invoice.paper.conditions_title": "الشروط والأحكام",
|
||||
"invoice.paper.notes_title": "ملاحظات",
|
||||
"item_entry.paper.item_name": "اسم الصنف",
|
||||
"item_entry.paper.rate": "السعر",
|
||||
"item_entry.paper.quantity": "الكمية",
|
||||
"item_entry.paper.total": "إجمالي",
|
||||
"estimate.paper.estimate": "عرض أسعار",
|
||||
"estimate.paper.billed_to": "عرض أسعار إلي",
|
||||
"estimate.paper.estimate_date": "تاريخ العرض",
|
||||
"estimate.paper.estimate_number": "رقم العرض",
|
||||
"estimate.paper.expiration_date": "تاريخ انتهاء الصلاحية",
|
||||
"estimate.paper.conditions_title": "الشروط والأحكام",
|
||||
"estimate.paper.notes_title": "ملاحظات",
|
||||
"estimate.paper.amount": "قيمة العرض",
|
||||
"receipt.paper.receipt": "إيصال",
|
||||
"receipt.paper.billed_to": "الإيصال إلي",
|
||||
"receipt.paper.receipt_date": "تاريخ الإيصال",
|
||||
"receipt.paper.receipt_number": "رقم الإيصال",
|
||||
"receipt.paper.conditions_title": "الشروط والأحكام",
|
||||
"receipt.paper.notes_title": "ملاحظات",
|
||||
"receipt.paper.receipt_amount": "قيمة الإيصال"
|
||||
}
|
||||
@@ -161,6 +161,7 @@
|
||||
"Opening Balance": "Opening balance",
|
||||
"Total {{accountName}}": "Total {{accountName}}",
|
||||
"invoice.paper.invoice": "Invoice",
|
||||
"invoice.paper.due_amount": "Due amount",
|
||||
"invoice.paper.billed_to": "Billed to",
|
||||
"invoice.paper.invoice_date": "Invoice date",
|
||||
"invoice.paper.invoice_number": "Invoice No.",
|
||||
@@ -178,7 +179,7 @@
|
||||
"estimate.paper.expiration_date": "Expiration date",
|
||||
"estimate.paper.conditions_title": "Conditions & terms",
|
||||
"estimate.paper.notes_title": "Notes",
|
||||
"estimate.paper.due_amount": "Due amount",
|
||||
"estimate.paper.amount": "Estimate amount",
|
||||
"receipt.paper.receipt": "Receipt",
|
||||
"receipt.paper.billed_to": "Billed to",
|
||||
"receipt.paper.receipt_date": "Receipt date",
|
||||
|
||||
Reference in New Issue
Block a user