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

Custom tags #359

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Custom tags #359

wants to merge 3 commits into from

Conversation

zverev
Copy link

@zverev zverev commented Feb 20, 2014

Hello,

I've tried to make an internationalization for our project using mustache, but didn't find a rather simple way to do it. So i've thought about using custom tag for this task. For example {{i some text}}.
Does this idea corresponds to the philosophy of mustache.js?

Best regards,
Alexander

@dasilvacontin
Copy link
Collaborator

Could you explain, give an use example? If I understand correctly, for internationalisation, couldn't you just pass an object with a different set of strings?

@phillipj
Copy link
Collaborator

phillipj commented Jan 6, 2015

This isnt just targeted at internationalization is it? As it enables extensibility it resembles a simple plugin system IMO. Could it be something to work on related to plugins / pragmas as mentioned in #406?

@zverev
Copy link
Author

zverev commented Jan 7, 2015

@dasilvacontin
According to this pull-request:

var translationsHash = {
    firstName: "First name",
    lastName: "Last name"
};

Mustache.addCustomTag('i', function(contents, value) {
    return translationsHash[contents];
});

Template may look like this:

<div class="user">
    <div class="user-firstName">{{i lastName}}: {{firstName}}</div>
    <div class="user-lastName">{{i firstName}}: {{lastName}}</div>
</div>

If we use this approach, we don't need to pass strings at all.

@phillipj
Actually Handlebars has this feature (helpers), so we switched to it. Now I'm not sure, that mustache.js really need custom tags.

@dasilvacontin
Copy link
Collaborator

@zverev, thanks for the template example.

Couldn't you just pass a different data/model object or a modified one to Mustache.render?

@zverev
Copy link
Author

zverev commented Jan 28, 2015

@dasilvacontin
Yes, I certainly could. But this method allows to avoid it. Also in my case I have some global translations, that are used by multiple components (e.g. button titles such as 'ok', 'cancel'). Without 'i' tag I would have to pass them manually.
Sorry for the late reply.

@dasilvacontin
Copy link
Collaborator

No worries. I see what you mean.

We certainly need some kind of Plugin API. Having a Plugin API would make solving this issue something trivial. I think we should discuss how we approach adding a Plugin API in a separate issue.

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

Successfully merging this pull request may close these issues.

None yet

3 participants