Skip to content

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

@longdoan7421

Description

@longdoan7421

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions