__n function doesn't know how to consume the JSON generated by the i18n package itself. The console.log( "__n :", i18n.__n( '%s cat', '%s cats', 1 ) ) line only works because the console.log( "__ :", i18n.__( '%s cat', 1 ) ) line causes "%s cat": "%s cat" to be generated in the JSON before it being called, and reads from this key. When essentially the same line, i.e., console.log( "__n :", i18n.__n( '%s dog', '%s dogs', 1 ) ) is being it generates a different (and logical) hash map in JSON for the key"%s dog", and then for some reason it cannot read it.
CLI output
user@device tmp % node index.js
current locale: en
__ : 1 cat
__mf : 1 cat
__n : 1 cat
__n : 1 cat
/Users/user/.../tmp/node_modules/i18n/i18n.js:451
.toLowerCase()
^
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at Object.i18nTranslatePlural [as __n] (/Users/user/.../tmp/node_modules/i18n/i18n.js:451:12)
at file:///Users/user/.../tmp/index.js:21:29
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:120:12)
Node.js v21.6.2
Also if I comment out the console.log( "__n :", i18n.__n( '%s dog', '%s dogs', 1 ) ) line after en.json has been generated, the executions fails in the same way at the line console.log( "__n :", i18n.__n( '%s dog', 1 ) ).
Note
Using __n in different manner works, but it's too unreadable for normal usage.
__n
not working as per documentation in the descriptionDevice specifications
Probably not all of the following is needed but her's the info just to be safe.
Minimal project
Initial files
package.json
index.js
Generated after running
node index.js
in the Terminallocale/de.json
locale/en.json
Issue
__n
function doesn't know how to consume the JSON generated by thei18n
package itself. Theconsole.log( "__n :", i18n.__n( '%s cat', '%s cats', 1 ) )
line only works because theconsole.log( "__ :", i18n.__( '%s cat', 1 ) )
line causes"%s cat": "%s cat"
to be generated in the JSON before it being called, and reads from this key. When essentially the same line, i.e.,console.log( "__n :", i18n.__n( '%s dog', '%s dogs', 1 ) )
is being it generates a different (and logical) hash map in JSON for the key"%s dog"
, and then for some reason it cannot read it.CLI output
Also if I comment out the
console.log( "__n :", i18n.__n( '%s dog', '%s dogs', 1 ) )
line after en.json has been generated, the executions fails in the same way at the lineconsole.log( "__n :", i18n.__n( '%s dog', 1 ) )
.Note
Using
__n
in different manner works, but it's too unreadable for normal usage.adds to en.json
and outputs
as expected.