[Owncloud] JavaScript translation function with interpolation support
Thomas Tanghus
thomas at tanghus.net
Mon Sep 17 11:15:24 UTC 2012
On Monday 17 September 2012 12:32 Thomas Tanghus wrote:
> On Monday 17 September 2012 10:18 Thomas Müller wrote:
> > Hi,
> >
> > maybe I'm not looking at the correct file [0], but we have no support for
> > string interpolation on the translation function in JavaScript - right?
> >
> > Any specific reason for this?
> > Who can implement it?
>
> I have used [1] for variable interpolation in a micro-templating jquery
> plugin in my process of rewriting the Contacts UI. Not extending the String
> prototype as in the example, but as a separate function.
> I guess something like that could be used, maybe by simply adding an
> optional variable map/object argument to the t() function.
>
> [1]
> http://stackoverflow.com/questions/1408289/best-way-to-do-variable-interpol
> ation-in-javascript#answer-1408373
And then I might as well test it ;) Diff attached.
Use as:
t('app', 'Today is {day}, {date}. {month}', {day: 'Monday', date: 17, month: 'September'});
--
Med venlig hilsen / Best Regards
Thomas Tanghus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: js.js.diff
Type: text/x-patch
Size: 1413 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/owncloud/attachments/20120917/92005de1/attachment.bin>
More information about the Owncloud
mailing list