/** * @mixxtor/adonisjs-translader * * (c) Mixxtor * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import type { ApplicationService } from '@adonisjs/core/types' import { createTranslator } from '@mixxtor/translader' import type { TranslationConfig, TranslationService } from '../src/types.js' import { configProvider } from '@adonisjs/core' import { RuntimeException } from '@adonisjs/core/exceptions' /** * Extend AdonisJS container bindings with translation service */ declare module '@adonisjs/core/types' { interface ContainerBindings { 'translation.manager': TranslationService } } export default class TranslationProvider { constructor(protected app: ApplicationService) {} /** * Register translation service */ async register() { this.app.container.singleton('translation.manager', async () => { const translationConfigProvider = this.app.config.get('translation') if (!translationConfigProvider) { throw new RuntimeException( 'Translation configuration not found. Make sure you have a "config/translation.ts" file with "defineConfig" export' ) } const config = await configProvider.resolve(this.app, translationConfigProvider) if (!config) { throw new RuntimeException('Invalid "config/translation.ts" file. Make sure you are using the "defineConfig" method') } // Create translation service with all providers return createTranslator(config) }) } /** * Boot the provider */ async boot() { // Nothing to boot } /** * Shutdown the provider */ async shutdown() { // Nothing to shutdown } }