You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
import {Singleton, Inject} from '../../di'
|
|
import {CommandLine} from '../../cli'
|
|
import {InjectRequestLocale} from '../modules/InjectRequestLocale'
|
|
import {templateLocale} from '../template/locale'
|
|
import {Unit} from '../../lifecycle/Unit'
|
|
import {HTTPKernel} from '../../http/kernel/HTTPKernel'
|
|
import {Config} from '../../service/Config'
|
|
import {Logging} from '../../service/Logging'
|
|
|
|
/**
|
|
* Application unit to register @extollo/i18n resources.
|
|
*/
|
|
@Singleton()
|
|
export class Internationalization extends Unit {
|
|
@Inject()
|
|
protected readonly kernel!: HTTPKernel
|
|
|
|
@Inject()
|
|
protected readonly config!: Config
|
|
|
|
@Inject()
|
|
protected readonly logging!: Logging
|
|
|
|
@Inject()
|
|
protected readonly cli!: CommandLine
|
|
|
|
/**
|
|
* Registers the locale template and middleware, if enabled by config.
|
|
*
|
|
* You can set the "locale.enable" config property to `false` to disable
|
|
* the InjectRequestLocale HTTP kernel module.
|
|
*/
|
|
up(): void {
|
|
this.logging.debug(`Registering locale template with CLI...`)
|
|
this.cli.registerTemplate(templateLocale)
|
|
|
|
if ( this.config.get('locale.enable', true) ) {
|
|
this.kernel.register(InjectRequestLocale).before()
|
|
} else {
|
|
this.logging.warn(`@extollo/i18n is registered, but disabled by config. Localization will not be done per-request.`)
|
|
}
|
|
}
|
|
}
|