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

Object properties #63

Open
chikamichi opened this issue Dec 19, 2014 · 4 comments
Open

Object properties #63

chikamichi opened this issue Dec 19, 2014 · 4 comments

Comments

@chikamichi
Copy link

Hi (again),

More or less on the same topic as #61, I wonder whether it would be nice to add support for hash properties. A use-case to illustrate this:

# data
fullname: @user.fullname() # for instance ^^

# template
<span class="greeting">{{ i18n "ui.msg.welcome" {name: fullname} }}</span>

where the "ui.msg.welcome" I18N key would typically be defined as:

# en.coffee
ui:
  msg:
    welcome: "Welcome %{name}"

# fr.coffee
ui:
  msg:
    welcome: "Bienvenue %{name}"

That is, given a fullname property available in the rendering context (data), make it possible to pass it along through an object.

The current parser can't handle that just yet, but thanks to #62, one can workaround this by wrapping the object:

# data
fullname: {fullname: @user.fullname()}

# template
<span class="greeting">{{ i18n "ui.msg.welcome" fullname }}</span>

Between those two options, I don't know which one reads better but, altough I have the feeling that the second option is "fine", the wrapping is cumbersome and somehow less standard than the first option where the object is written in the template.

In the simple cases where there is only one variable to pass around, this wrapping can be automated, but if several variables must be merged in the same object (for instance, {name: fullname, gender: gender, vip: isVIP} to interpolate a complex sentence), then automation is not an option anymore. It is still possible to manually wrap the object beforehand, but being able to write the object within the template may feel more straightforward.

So it basically boils down to template management preferences 🔪

What do you think?

@tbranyen
Copy link
Owner

Have you tried using a filter for this? Seems like it might work better than wrapping your properties as objects in the template data.

@chikamichi
Copy link
Author

I must say I did not yet.

@tbranyen
Copy link
Owner

Although whether or not filters will work as arguments is also a good question. They probably don't :-/

@tbranyen
Copy link
Owner

tbranyen commented May 3, 2015

At the moment, you'd have to do this in the business layer. In the future (say version 1.0), I'd expect to see parenthesis added to preserve context. So something like this would be possible:

{{ "ui.msg.welcome"|i18n(fullname|withKeyName('name')) }}

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