meteor-messageformat icon indicating copy to clipboard operation
meteor-messageformat copied to clipboard

Per-template, enumerated keys

Open tvld opened this issue 10 years ago • 4 comments

What if mf would keep the scope of keys within the context of a template, so we just can use a small integer as key? This integer is unique for the template only so text can be rearranged without loosing translations.

Example myfile.html

{{mf 111 'Orhpan and abandoned childs' }}

<template name="home"> <h1>{{mf 1 'Welcome'}}</h1> <p>{{mf 2 'This is nice to see you'}}</p> </template>

<template name="apage"> {{mf 16 'A page of us'}} <p>{{mf 2 'The quick brown fox....'}}</p> </template>

<template name="home" mf_key_prefix="editorialpage"> <h3>{{mf 2 'Welcome editor'}}</h3> <i>{{mf 7 'my editing life....'}}</i> </template>

This would give parameters:

myfile-111 home_1 home_2 apage_2 apage_16 editorialpage2 editorialpage7

Parsing Logic

  • if the mf_extract finds a string, as per the current definition, all logic is as is now
  • if mf_extract finds first (key) parameter of int, mf knows to treat keys as local, trying in this order to find a prefix:
    • attribute 'mf_key_prefix' if it exists in tempalte
    • the template name+'-' as prefix.
    • file name +'-' as the context.
  • multiple use of a certain int in one context, will throw an error

Tom

tvld avatar Jul 04 '15 08:07 tvld

Thanks for your comments, Tom, it does sound like a good idea. There was an idea before to make the keys local to the template but as far as I remember, it was not possible a while ago for the mf_extract to discover what template the key was in (in a feasible way).

Things have probably changed so far so it's worth looking into. I'm sure @gadicc can say more

DSpeichert avatar Jul 04 '15 23:07 DSpeichert

Yeah, this is a very nice compromise. As @DSpeichert mentioned, we had wanted template localized before, and enumerating them is a great idea. The problem wasn't actually with mf_extract, but with figuring out what template we were being called from in Meteor. At the time it wasn't possible but indeed now it is. So let's leave this open and once we get passed a few more milestones on the v2 branch, it's something we can try out. We also discussed some ideas for renaming keys in https://github.com/gadicc/meteor-messageformat/issues/105.

gadicc avatar Jul 05 '15 08:07 gadicc

Thanks:) As per your comments I've updated initial post to allow easier discussion & development later.

tvld avatar Jul 05 '15 09:07 tvld

Awesome, shot :)

gadicc avatar Jul 05 '15 09:07 gadicc