Skip to content

Commit

Permalink
refactor: make i18n.config a public property
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 27, 2023
1 parent 80a289e commit cb51a2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/i18n_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class I18nManager {
/**
* i18n config
*/
#config: I18nManagerConfig
config: I18nManagerConfig

/**
* Reference to the emitter for emitting events
Expand Down Expand Up @@ -58,7 +58,7 @@ export class I18nManager {
* Reference to the default locale defined inside the config file
*/
get defaultLocale(): string {
return this.#config.defaultLocale
return this.config.defaultLocale
}

/**
Expand All @@ -73,7 +73,7 @@ export class I18nManager {
emitter: Emitter<{ 'i18n:missing:translation': MissingTranslationEventPayload } & any>,
config: I18nManagerConfig
) {
this.#config = config
this.config = config
this.#emitter = emitter
}

Expand All @@ -85,7 +85,7 @@ export class I18nManager {
* config file.
*/
supportedLocales() {
return this.#config.supportedLocales || this.#inferredLocales
return this.config.supportedLocales || this.#inferredLocales
}

/**
Expand Down Expand Up @@ -114,8 +114,8 @@ export class I18nManager {
* formatters after an instance of manager has been created
*/
if (!this.#formatter) {
const formatterFactory = this.#config.formatter
this.#formatter = formatterFactory(this.#config)
const formatterFactory = this.config.formatter
this.#formatter = formatterFactory(this.config)
}

return this.#formatter
Expand All @@ -140,8 +140,8 @@ export class I18nManager {
debug('loading translations')

const translationsStack = await Promise.all(
this.#config.loaders.map((loaderFactory) => {
return loaderFactory(this.#config).load()
this.config.loaders.map((loaderFactory) => {
return loaderFactory(this.config).load()
})
)

Expand All @@ -165,7 +165,7 @@ export class I18nManager {
* - Locales detected from translations
*/
this.#inferredLocales = [this.defaultLocale].concat(
this.#config.fallbackLocales ? Object.keys(this.#config.fallbackLocales) : []
this.config.fallbackLocales ? Object.keys(this.config.fallbackLocales) : []
)

/**
Expand Down Expand Up @@ -217,8 +217,8 @@ export class I18nManager {
/**
* Use explicitly defined fallback locale
*/
if (this.#config.fallbackLocales && this.#config.fallbackLocales[locale]) {
return this.#config.fallbackLocales[locale]
if (this.config.fallbackLocales && this.config.fallbackLocales[locale]) {
return this.config.fallbackLocales[locale]
}

/**
Expand Down Expand Up @@ -260,6 +260,6 @@ export class I18nManager {
* Otherwise returns undefined
*/
getFallbackMessage(identifier: string, locale: string): string | undefined {
return this.#config.fallback?.(identifier, locale)
return this.config.fallback?.(identifier, locale)
}
}
4 changes: 3 additions & 1 deletion stubs/config.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import app from '@adonisjs/core/services/app'
import { defineConfig, formatters, loaders } from '@adonisjs/i18n'

export default defineConfig({
const i18nConfig = defineConfig({
defaultLocale: 'en',
formatter: formatters.icu(),

Expand All @@ -23,3 +23,5 @@ export default defineConfig({
}),
],
})

export default i18nConfig

0 comments on commit cb51a2c

Please sign in to comment.