Skip to content

Commit

Permalink
refactor: rename messages to translations and write view related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Oct 7, 2021
1 parent aaca063 commit cabb541
Show file tree
Hide file tree
Showing 13 changed files with 516 additions and 146 deletions.
47 changes: 31 additions & 16 deletions adonis-typings/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ declare module '@ioc:Adonis/Addons/I18n' {
}

/**
* Messages formatter formats a string as per the defined
* Translations formatter formats a string as per the defined
* specification.
*/
export interface MessageFormatterContract {
export interface TranslationsFormatterContract {
name: string

/**
Expand Down Expand Up @@ -137,10 +137,10 @@ declare module '@ioc:Adonis/Addons/I18n' {
*/
export type I18nConfig = {
/**
* Messages format to use. Officially we support
* Translations format to use. Officially we support
* ICU only
*/
messagesFormat: string
translationsFormat: string

/**
* Default locale for the application. This locale is
Expand All @@ -150,7 +150,7 @@ declare module '@ioc:Adonis/Addons/I18n' {
defaultLocale: string

/**
* If not defined, we will rely on the messages to find the
* If not defined, we will rely on the translations to find the
* support locales
*/
supportedLocales?: string[]
Expand Down Expand Up @@ -194,12 +194,12 @@ declare module '@ioc:Adonis/Addons/I18n' {
export type LoaderExtendCallback = (manager: I18nManagerContract, config: any) => LoaderContract

/**
* Shape for the messages formatter extend callback
* Shape for the translations formatter extend callback
*/
export type FormatterExtendCallback = (
manager: I18nManagerContract,
config: I18nConfig
) => MessageFormatterContract
) => TranslationsFormatterContract

/**
* I18n manager shape
Expand All @@ -221,23 +221,38 @@ declare module '@ioc:Adonis/Addons/I18n' {
locale(locale: string): I18nContract

/**
* An array of locales for which the application has
* defined messages. These are user defined locales
* and not normalized "ISO 15897" strings
* An array of locales for which the application has defined
* translations. These are user defined locales and not
* normalized "ISO 15897" strings
*/
supportedLocales(): string[]

/**
* Loads messages using the registered loaders. The method
* returns in a noop after first call. Use "reloadMessages"
* to force reload
* Loads translations using the registered loaders. The method returns
* in a noop after first call. Use "reloadTranslations" to force
* reload
*/
loadMessages(): Promise<void>
loadTranslations(): Promise<void>

/**
* Reloads messages using the registered loaders
* Reloads translations using the registered loaders
*/
reloadMessages(): Promise<void>
reloadTranslations(): Promise<void>

/**
* Returns all the translations
*/
getTranslations(): Translations

/**
* Returns translations for a given locale
*/
getTranslationsFor(locale: string): Record<string, string>

/**
* Returns reference to the application formatter
*/
getFormatter(): TranslationsFormatterContract

/**
* Extend to add custom loaders and formatters
Expand Down
196 changes: 196 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@adonisjs/mrm-preset": "^4.1.2",
"@adonisjs/require-ts": "^2.0.8",
"@adonisjs/sink": "^5.1.6",
"@adonisjs/view": "^6.1.1",
"@poppinss/dev-utils": "^1.1.5",
"@types/luxon": "^2.0.4",
"@types/node": "^16.10.2",
Expand Down
3 changes: 2 additions & 1 deletion providers/I18nProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export default class I18nProvider {
public register() {
this.application.container.singleton('Adonis/Addons/I18n', () => {
const emitter = this.application.container.resolveBinding('Adonis/Core/Event')
const logger = this.application.container.resolveBinding('Adonis/Core/Logger')
const config = this.application.container.resolveBinding('Adonis/Core/Config').get('i18n', {})
return new I18nManager(this.application, emitter, config)
return new I18nManager(this.application, emitter, logger, config)
})
}

Expand Down
Loading

0 comments on commit cabb541

Please sign in to comment.