i18n-node-2 icon indicating copy to clipboard operation
i18n-node-2 copied to clipboard

Feature Request: General Place-holders

Open dortamur opened this issue 9 years ago • 2 comments

Would it be feasible to add support for general place-holders, where one localised string could refer to another one? This would enable common terms/phrases to be used in the content of others, without requiring parameter parsing at the code level.

For example;

{
   "contact service desk": "contact Service Desk (x3000)",
   "wrong id": "You've entered a wrong ID. Please try again, or {{contact service desk}} for further assistance",
   "db error": "Oops! Something is wrong with our servers. If this problem persists, please {{contact service desk}}"
}

In this way, any mention of contacting the Service Desk is consistent, and if the message (eg; the phone extension) changes, it's reflected across all other references.

Preferably, such a feature would be able to be enabled/disabled, and the place-holder syntax be customisable, to avoid clashes with real content syntax in templates, etc...

Here's an idea for an alternative syntax:

{
   "contact service desk": "contact Service Desk (x3000)",
   "wrong id": ["You've entered a wrong ID. Please try again, or %p for further assistance", "contact service desk"],
   "db error": ["Oops! Something is wrong with our servers. If this problem persists, please %p", "contact service desk"]
}

This syntax is similar to the "%s" place-holder syntax, but in this case, the substituted value is another i18n entry, named within the locales config.

dortamur avatar Dec 09 '15 04:12 dortamur

I do believe that is already working, by putting %s, and in argument another i18n.__ call

var greeting = i18n.__('Hello %s, how are you today? How was your %s?',
    'Marcus', i18n.__('weekend'));```

gjuchault avatar Jan 05 '16 12:01 gjuchault

I know you can pass in parameters from code - my suggestion is to support parameters internally to the list of localised strings. In that way, one string could include another, without the calling application needing to be aware that any parameter substitution is taking place.

In my example, I showed a string for contacting the servicedesk, and then referenced it in several other strings. If the contact details for the servicedesk ever changed, you'd only have to change the one string, rather than all the strings it might be referenced.

dortamur avatar Jan 12 '16 08:01 dortamur