Skip to content

__n() throws error if setLocale not called, despite defaultLocale #429

@ucacoin

Description

@ucacoin

HI,

if you call __n() without setLocale beforehand it will throw:

var lc = targetLocale.toLowerCase().split(/[_-\s]+/)
                              ^

TypeError: Cannot read property 'toLowerCase' of undefined
    at Object.i18nTranslatePlural [as __n] (path/node_modules/i18n/i18n.js:371:31)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)

Even if you define a default locale with:

i18n.configure({
    locales:['en', 'de'],
    directory: __dirname + '/../locales',
    defaultLocale: 'de',
});

There should be a fallback that if no targetLocale is found the defaultLocale should be used.

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