formatjs / dust-intl

Dust helpers for internationalization.
http://formatjs.io/dust/
Other
48 stars 11 forks source link

body replacement support #24

Closed willthai closed 10 years ago

willthai commented 10 years ago

I have a use case as such:

{@i18n_string _key="ALT_TEXT" _name="altText"} {@img src="{asseturl}" alt="{altText}" /} {/i18n_string}

Can I get this supported? Thanks

caridy commented 10 years ago

/cc @drewfish

drewfish commented 10 years ago

Would something like this work instead? {@img src="{asseturl}" alt="{@i18n _key='ALT_TEXT'}" /}

willthai commented 10 years ago

@drewfish afaik, a dust helper inside a dust helper doesn't work

drewfish commented 10 years ago

It seems like you could use a helper that puts the results of part of the template into a variable in the context. I searched a little bit for a helper to do this but couldn't find one. (BTW, there's nothing intl-specific about this.)

I was able to hack together a helper that works with the dustjs-linkedin version of dust:

Dust.helpers.export = function(chunk, context, bodies, params) {
    return chunk.capture(bodies.block, context, function(out, chunk2) {
        context.current()[params.to] = out;
        chunk2.end('');
    });
};

You can then use it like {@export to="foo"}I like {color} balloons.{/export}...{foo} and {color:'red'} which should return ...I like red balloons.. In your case case you'd do something like {@export to="altText"}{@i18n _key='ALT_TEXT'}{/export}{@img src=asseturl alt=altText /} .

caridy commented 10 years ago

closing this issue since it is not intl specific.