Opened 17 years ago

Last modified 17 years ago

#4414 closed

I18N Javascript interpolate function — at Initial Version

Reported by: tobias@… Owned by: Malcolm Tredinnick
Component: Internationalization Version: dev
Severity: Keywords: i18n javascript interpolate
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

why do you interpolate javascript translation strings just once? i currently have the case, that i have to replace like this:

var transObj = { numShown: numShown, numAvail: numAvail};
interpolate(gettext("%(numShown)s out of %(numAvail)s"), transObj, true));

Index: views/i18n.py
===================================================================
--- views/i18n.py (revision 5038)
+++ views/i18n.py (working copy)
@@ -69,9 +69,9 @@

InterPolate = r"""
function interpolate(fmt, obj, named) {

if (named) {

  • return fmt.replace(/%\(\w+\)s/, function(match){return String(obj[match.slice(2,-2)])});

+ return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});

} else {

  • return fmt.replace(/%s/, function(match){return String(obj.shift())});

+ return fmt.replace(/%s/g, function(match){return String(obj.shift())});

}

}
"""

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top