nestjs-i18n
Advanced tools
Comparing version 2.0.2 to 2.1.0
import { DynamicModule } from '@nestjs/common'; | ||
export interface I18nOptions { | ||
path: string; | ||
fallbackLanguage?: string; | ||
} | ||
import { I18nAsyncOptions, I18nOptions } from './interfaces/i18n-options.interface'; | ||
export declare class I18nModule { | ||
static forRoot(options: I18nOptions): DynamicModule; | ||
static forRootAsync(options: I18nAsyncOptions): DynamicModule; | ||
private static createAsyncOptionsProvider; | ||
} |
@@ -8,4 +8,12 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var I18nModule_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var I18nModule_1; | ||
const common_1 = require("@nestjs/common"); | ||
@@ -22,9 +30,28 @@ const i18n_constants_1 = require("./i18n.constants"); | ||
module: I18nModule_1, | ||
providers: [ | ||
i18nOptions, | ||
i18n_service_1.I18nService, | ||
], | ||
providers: [i18n_service_1.I18nService, i18nOptions], | ||
exports: [i18n_service_1.I18nService], | ||
}; | ||
} | ||
static forRootAsync(options) { | ||
const asyncProvider = this.createAsyncOptionsProvider(options); | ||
return { | ||
module: I18nModule_1, | ||
providers: [asyncProvider, i18n_service_1.I18nService], | ||
exports: [i18n_service_1.I18nService], | ||
}; | ||
} | ||
static createAsyncOptionsProvider(options) { | ||
if (options.useFactory) { | ||
return { | ||
provide: i18n_constants_1.I18N_OPTIONS, | ||
useFactory: options.useFactory, | ||
inject: options.inject || [], | ||
}; | ||
} | ||
return { | ||
provide: i18n_constants_1.I18N_OPTIONS, | ||
useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () { return yield optionsFactory.createI18nOptions(); }), | ||
inject: [options.useClass || options.useExisting], | ||
}; | ||
} | ||
}; | ||
@@ -31,0 +58,0 @@ I18nModule = I18nModule_1 = __decorate([ |
@@ -1,2 +0,2 @@ | ||
import { I18nOptions } from '../i18n.module'; | ||
import { I18nOptions } from '../interfaces/i18n-options.interface'; | ||
export declare class I18nService { | ||
@@ -3,0 +3,0 @@ private readonly i18nOptions; |
@@ -53,3 +53,5 @@ "use strict"; | ||
this.logger.error(message); | ||
if ((this.i18nOptions.fallbackLanguage !== null || this.i18nOptions.fallbackLanguage !== undefined) && lang !== this.i18nOptions.fallbackLanguage) { | ||
if ((this.i18nOptions.fallbackLanguage !== null || | ||
this.i18nOptions.fallbackLanguage !== undefined) && | ||
lang !== this.i18nOptions.fallbackLanguage) { | ||
return this.translate(this.i18nOptions.fallbackLanguage, key, args); | ||
@@ -56,0 +58,0 @@ } |
{ | ||
"name": "nestjs-i18n", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "", | ||
"author": "Toon van Strijp", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/ToonvanStrijp/nestjs-i18n" | ||
"type": "git", | ||
"url": "https://github.com/ToonvanStrijp/nestjs-i18n" | ||
}, | ||
@@ -21,14 +21,14 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@nestjs/common": "^6.0.2", | ||
"@nestjs/core": "^6.0.2", | ||
"@nestjs/common": "^6.2.4", | ||
"@nestjs/core": "^6.2.4", | ||
"@types/glob": "^7.1.1", | ||
"@types/node": "^11.11.6", | ||
"@types/node": "^12.0.4", | ||
"@types/string-format": "^2.0.0", | ||
"husky": "1.3.1", | ||
"lint-staged": "8.1.5", | ||
"prettier": "1.16.4", | ||
"typescript": "3.3.4000" | ||
"husky": "2.3.0", | ||
"lint-staged": "8.1.7", | ||
"prettier": "1.17.1", | ||
"typescript": "3.5.1" | ||
}, | ||
"dependencies": { | ||
"glob": "^7.1.3", | ||
"glob": "^7.1.4", | ||
"string-format": "^2.0.0" | ||
@@ -35,0 +35,0 @@ }, |
@@ -57,2 +57,22 @@ ## Description | ||
``` | ||
#### using forRootAsync | ||
``` | ||
import { Module } from '@nestjs/common'; | ||
import * as path from 'path'; | ||
import { I18nModule } from './modules/i18n/i18n.module'; | ||
@Module({ | ||
imports: [ | ||
I18nModule.forRootAsync({ | ||
useFactory: (config: ConfigurationService) => ( | ||
{ path: configService.i18nPath, fallbackLanguage: 'es' } | ||
), | ||
inject: [ConfigurationService] | ||
}), | ||
], | ||
controllers: [] | ||
}) | ||
export class AppModule {} | ||
``` | ||
### Using translation service | ||
@@ -59,0 +79,0 @@ ``` |
201
92
11831
15
Updatedglob@^7.1.4