i18n-node icon indicating copy to clipboard operation
i18n-node copied to clipboard

[Bug] translation API is returning `undefined` when provided locale is `undefined` or `null`

Open longdoan7421 opened this issue 2 years ago • 0 comments

Hi, the current API i18n.__ is returning undefined value if the provided locale is undefined or null even when the configuration has retryInDefaultLocale = true.

Steps to reproduce

const i18n = require('i18n');

i18n.configure({
  locales: ['en', 'de'],
  defaultLocale: 'en',
  directory: './locales',
  updateFiles: false,
  retryInDefaultLocale: true,
});

console.log(i18n.__({ phrase: 'Hello', locale: undefined})); // undefined

Environment:

  • NodeJS: v14+
  • i18n-node version: 0.15.1

Actual behavior

Return undefined.

Expected behavior

Return translated string in default locale if retryInDefaultLocale = true and perhaps even in case retryInDefaultLocale = false.

longdoan7421 avatar Oct 02 '22 17:10 longdoan7421