bugGNU gettext - Bugs: bug #60027, Supporting template interpolation...


You are not allowed to post comments on this tracker with your current authentication level.

bug #60027: Supporting template interpolation and tags in JavaScript

Submitter:  Evan Welsh <ewlsh>
Submitted:  Tue 09 Feb 2021 06:33:53 AM UTC
Category:  JavaScript Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open

Tue 09 Feb 2021 06:14:15 PM UTC, comment #1: 

I'd like to express my support for this — backtick strings with interpolation have been around for long enough in JavaScript that there are now plenty of JS programmers who have never experienced the language without them, and so it's natural for them to want to use these strings with gettext.

I like this proposal because it neatly avoids the problems of code inside backtick strings like `My number is ${Math.random()}`, which would just show up as "My number is ${0}" in the messages file.

Many projects using GJS are written in mixed C and JavaScript so xgettext is the natural (and possibly only) tool that will translate strings from a codebase in both of these languages. In GJS we would be eager to implement support for this proposed template tag, but there is no point for us to add it unless xgettext will support it.

Philip Chimento <ptomato>
Tue 09 Feb 2021 06:33:53 AM UTC, original submission:  

GJS hopes to deprecate its formatting module in favor of template strings. Such a change would require xgettext changes to continue supporting translated strings. We're hoping to discuss whether xgettext would ship support for a potential API if we were to implement it in GJS or alternatively what API xgettext would be interested in shipping.

The GJS proposal is currently at https://gitlab.gnome.org/GNOME/gjs/-/issues/374

The goal of the initial proposal is to make it close enough to the existing syntax that it is not overly challenging to parse or implement.

## The API

The API could potentially look like:

gettext(msgid`A sentence with an ${argument}`)

where `msgid` is a template tag which handles the appropriate conversions before passing it to a gettext function.

The msgid would be the same string with any top-level expressions replaced by their index:

msgid "A sentence with an ${0}"


msgid "A sentence with a ${0} and a ${1}"

### Shortcuts

A shortcut for gettext could also be included:

_`A dog named ${name}`

To simplify the very common...

_(msgid`A dog named ${name}`)

Evan Welsh <ewlsh>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #50941:  0001-Support-template-strings-with-substitutions.patch added by ewlsh (12KiB - text/x-patch - Initial patch for supporting template strings with substitutions.)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by ptomato (Posted a comment)
  • -email is unavailable- added by ewlsh (Submitted the item)
  • -email is unavailable- added by ewlsh

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-28 ewlsh Attached File- Added 0001-Support-template-strings-with-substitutions.patch, #50941
    2021-02-09 ewlsh Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-c54d.
    Corresponding source code