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

Error when using inside components #2

Open
andresilvasantos opened this issue Oct 9, 2017 · 5 comments
Open

Error when using inside components #2

andresilvasantos opened this issue Oct 9, 2017 · 5 comments

Comments

@andresilvasantos
Copy link

I'm getting this error - Cannot read property 'req' of undefined - when using it like this:

class {
}

<i18n-var/>
<h2>${i18n('home.slogan')}</h2>

If I remove the class definition, it works without errors.
Do you know what the problem might be?

@gunjam
Copy link
Owner

gunjam commented Oct 9, 2017

Hi,

This is designed to be used server side on the assumption you're using i18next middleware in something like express. The 'of undefined' will be the output stream.

I should have probably made that clear in the documentation!

@andresilvasantos
Copy link
Author

Yes, I'm using i18next middleware with express.
And I'm rendering pages this way: res.marko(require(...), data);
I noticed you're calling the t() function from out.stream.req, I even refactored the code to work with out.global.i18n, but almost same problem.

I just don't understand why the pages render correctly, successfully translating the page, but printing that error on browser's console.
And when I remove the class {}, everything works as expected. What's the problem I'm not seeing when dealing with components?

And thank you for your quick reply!

@gunjam
Copy link
Owner

gunjam commented Oct 9, 2017

Adding a class {} section declarings the client side widget code, that must be causing the .t() funciton to be called clientside as well as I guess? Maybe there's a way around that. For now I'd just avoid adding a class{} section if you don't need one.

@andresilvasantos
Copy link
Author

The problem is that I have lots of routes with client side code that need translations. But no worries, I'll try to see if someone in gitter have a workaround for this. I'll keep you posted!

@gunjam
Copy link
Owner

gunjam commented Oct 9, 2017

Thanks, currently I'm only using the server side rendering aspects of marko in my services, so I haven't encounter this issue.

If you can find a way to fix it, or better yet, add client side translation support into component, that would be great!

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