Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass mongoose object to i18next translate fn #388

Closed
kirrg001 opened this issue May 12, 2015 · 8 comments
Closed

pass mongoose object to i18next translate fn #388

kirrg001 opened this issue May 12, 2015 · 8 comments

Comments

@kirrg001
Copy link

hey,

when i pass a mongoose object to the i18next translate fn, my whole node.js crashes.

/Users/kirrg/dev/avuba/avb-api-v2/node_modules/winston/lib/winston/common.js:242
        output += '\n' + stack.map(function (s) {
                               ^
TypeError: Cannot call method 'map' of undefined
    at Object.exports.log (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/winston/lib/winston/common.js:242:32)
    at Console.log (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/winston/lib/winston/transports/console.js:68:19)
    at Transport.logException (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/winston/lib/winston/transports/transport.js:124:8)
    at logAndWait (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/winston/lib/winston/logger.js:631:15)
    at /Users/kirrg/dev/avuba/avb-api-v2/node_modules/async/lib/async.js:125:13
    at Array.forEach (native)
    at _each (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/async/lib/async.js:46:24)
    at Object.async.each (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/async/lib/async.js:124:9)
    at Logger._uncaughtException (/Users/kirrg/dev/avuba/avb-api-v2/node_modules/winston/lib/winston/logger.js:654:9)
    at process.emit (events.js:117:20)
    at process._fatalException (node.js:272:26)

i took me 30minutes to find out that i18next is responsible for this error, because there is no stack information about it.

so when i convert the mongoose object to a javascript object (.toObject) it works.

maybe you can give me input.

thanks
kirrg

@jamuhl
Copy link
Member

jamuhl commented May 12, 2015

why you pass a mongoose object to translation function?

@kirrg001
Copy link
Author

it was by mistake. i never had issues with other libraries passing in a mongoose object.

@jamuhl
Copy link
Member

jamuhl commented May 12, 2015

PR optimizing your situation would be welcome.

@kirrg001
Copy link
Author

i was not able to debug your code, sorry.
maybe you can tell which file is maybe causing this problem.
thanks

@jamuhl
Copy link
Member

jamuhl commented May 18, 2015

the options object passed to t function is used to apply replacements on keys.

so complexe structures might break that: https://github.com/i18next/i18next/blob/master/src/i18next.translate.js#L1

@kirrg001
Copy link
Author

i started with a PR, but your tests are red on master

Safari 8.0 (Mac) i18next translation functionality interpolation - replacing values inside a string default i18next way it should replace passed in key/values in replace member FAILED
    expected 'added __toAdd__' to equal 'added something'
    assert@/Users/kirrg/dev/i18next/test/libs/expect.js:99:22
    equal@/Users/kirrg/dev/i18next/test/libs/expect.js:200:16
    /Users/kirrg/dev/i18next/test/libs/expect.js:73:29
    /Users/kirrg/dev/i18next/test/test.js:1764:88
    /Users/kirrg/dev/i18next/test/test.js:1753:31
    init@/Users/kirrg/dev/i18next/bin/i18next-latest.js:6:50818
    /Users/kirrg/dev/i18next/test/test.js:1752:20
Safari 8.0 (Mac) i18next translation functionality interpolation - replacing values inside a string default i18next way it should escape dollar signs in replacement values FAILED
    expected 'added __toAdd__' to equal 'added $&'
    assert@/Users/kirrg/dev/i18next/test/libs/expect.js:99:22
    equal@/Users/kirrg/dev/i18next/test/libs/expect.js:200:16
    /Users/kirrg/dev/i18next/test/libs/expect.js:73:29
    /Users/kirrg/dev/i18next/test/test.js:1779:68
    /Users/kirrg/dev/i18next/test/test.js:1753:31
    init@/Users/kirrg/dev/i18next/bin/i18next-latest.js:6:50818
    /Users/kirrg/dev/i18next/test/test.js:1752:20
Safari 8.0 (Mac) i18next translation functionality interpolation - replacing values inside a string default i18next way - with escaping interpolated arguments per default it should escape dollar signs in replacement values FAILED
    expected 'added __toAdd__amp;' to equal 'added $&'
    assert@/Users/kirrg/dev/i18next/test/libs/expect.js:99:22
    equal@/Users/kirrg/dev/i18next/test/libs/expect.js:200:16
    /Users/kirrg/dev/i18next/test/libs/expect.js:73:29
    /Users/kirrg/dev/i18next/test/test.js:1892:68
    /Users/kirrg/dev/i18next/test/test.js:1875:33
    init@/Users/kirrg/dev/i18next/bin/i18next-latest.js:6:50818
    /Users/kirrg/dev/i18next/test/test.js:1872:20
Safari 8.0 (Mac) i18next translation functionality interpolation - replacing values inside a string default i18next way - with escaping interpolated arguments per default via options it should escape dollar signs in replacement values FAILED
    expected 'added __toAdd__amp;' to equal 'added $&'
    assert@/Users/kirrg/dev/i18next/test/libs/expect.js:99:22
    equal@/Users/kirrg/dev/i18next/test/libs/expect.js:200:16
    /Users/kirrg/dev/i18next/test/libs/expect.js:73:29
    /Users/kirrg/dev/i18next/test/test.js:1931:68
    /Users/kirrg/dev/i18next/test/test.js:1914:33
    init@/Users/kirrg/dev/i18next/bin/i18next-latest.js:6:50818
    /Users/kirrg/dev/i18next/test/test.js:1912:20
Safari 8.0 (Mac): Executed 160 of 160 (4 FAILED) (1.612 secs / NaN secs)

@jamuhl
Copy link
Member

jamuhl commented May 18, 2015

http://i18next.com/pages/test.html runs for me on safari and chrome

grunt test runs ok with phantom.js

@jamuhl jamuhl added the issue label May 18, 2015
@jamuhl
Copy link
Member

jamuhl commented Nov 29, 2015

closing this due upcoming v2: http://i18next.github.io/i18next.com/

PRs welcome

@jamuhl jamuhl closed this as completed Nov 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants