Skip to content

Commit

Permalink
i18n hooks: don't use typeof to check value falsiness (#28733)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Feb 5, 2021
1 parent a863239 commit 1f1bcc6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/i18n/src/create-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,22 @@ 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.
*
* @param {string} translation Translated text.
* @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',
Expand All @@ -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.
*
Expand All @@ -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',
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 1f1bcc6

Please sign in to comment.