diff --git a/packages/i18n/src/create-i18n.js b/packages/i18n/src/create-i18n.js index 4d2105cd5a642..de1440c4ace56 100644 --- a/packages/i18n/src/create-i18n.js +++ b/packages/i18n/src/create-i18n.js @@ -154,16 +154,15 @@ export const createI18n = ( initialData, initialDomain, hooks ) => { }; /** @type {GetFilterDomain} */ - const getFilterDomain = ( domain ) => { - if ( typeof domain === 'undefined' ) { - return 'default'; - } - return domain; - }; + const getFilterDomain = ( domain = 'default' ) => domain; /** @type {__} */ const __ = ( text, domain ) => { let translation = dcnpgettext( domain, undefined, text ); + if ( ! hooks ) { + return translation; + } + /** * Filters text with its translation. * @@ -171,9 +170,6 @@ export const createI18n = ( initialData, initialDomain, hooks ) => { * @param {string} text Text to translate. * @param {string} domain Text domain. Unique identifier for retrieving translated strings. */ - if ( typeof hooks === 'undefined' ) { - return translation; - } translation = /** @type {string} */ ( /** @type {*} */ hooks.applyFilters( 'i18n.gettext', @@ -195,6 +191,10 @@ export const createI18n = ( initialData, initialDomain, hooks ) => { /** @type {_x} */ const _x = ( text, context, domain ) => { let translation = dcnpgettext( domain, context, text ); + if ( ! hooks ) { + return translation; + } + /** * Filters text with its translation based on context information. * @@ -203,9 +203,6 @@ export const createI18n = ( initialData, initialDomain, hooks ) => { * @param {string} context Context information for the translators. * @param {string} domain Text domain. Unique identifier for retrieving translated strings. */ - if ( typeof hooks === 'undefined' ) { - return translation; - } translation = /** @type {string} */ ( /** @type {*} */ hooks.applyFilters( 'i18n.gettext_with_context', @@ -235,9 +232,10 @@ export const createI18n = ( initialData, initialDomain, hooks ) => { plural, number ); - if ( typeof hooks === 'undefined' ) { + if ( ! hooks ) { return translation; } + /** * Filters the singular or plural form of a string. * @@ -278,9 +276,10 @@ export const createI18n = ( initialData, initialDomain, hooks ) => { plural, number ); - if ( typeof hooks === 'undefined' ) { + if ( ! hooks ) { return translation; } + /** * Filters the singular or plural form of a string with gettext context. *