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

res.locals is not by default accessible within the executing context #55

Open
ilyabreev opened this issue Feb 28, 2015 · 7 comments
Open
Labels

Comments

@ilyabreev
Copy link

Can't use i18n functions in vash view just like that:

@__("i18n_key")

Any workarounds?

@kirbysayshi
Copy link
Owner

What i18n functions are you trying to use? __() is not a standard JS API as far as I know.

@ilyabreev
Copy link
Author

I am trying to use function __()

There is i18n module: https://github.com/mashpie/i18n-node

In ejs view i can use it like that:

<%= __('Hello') %>

but in vash view i need to access function __() through @model

@model.__('Hello')

Is using @model really necessary?

@kirbysayshi
Copy link
Owner

Vash doesn't have any knowledge of the locals property that i18n-node uses for ejs, so there isn't an easy way to expose something to every template as a free variable. I suppose you could also useWith (https://github.com/kirbysayshi/vash#vash-config-usewith), and then ensure that __() is attached to whatever you pass in to vash.

There's another option though. You could attach __ to vash.helpers.__, and then access it at html.__(). Or even something not as gross looking like vash.helpers.txt and then html.txt().

@ilyabreev
Copy link
Author

Oh, thank you a lot, man! This is really cool tip.

I missed one important point though.
I am using vash with express and expecting that vash is express-compliant. I think that supporting a locals property for express (as in other template engines) may be a great feature.

@kirbysayshi kirbysayshi changed the title i18n integration res.locals is not by default accessible within the executing context Mar 2, 2015
@kirbysayshi
Copy link
Owner

I'll try to look into adding locals support via express, but don't have an estimate on when that might happen. I have to investigate a bit more into how they actually behave, but it's probably doable.

@joevolcano
Copy link

How can I use app.locals or functions added to the model I am passing to the render method?

@ilyabreev
Copy link
Author

Any progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants