bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gettext feature request


From: Léa Gris
Subject: Re: gettext feature request
Date: Fri, 13 Aug 2021 20:01:35 +0200
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 13/08/2021 à 18:14, Jean-Jacques Brucker écrivait :
Le 12/08/2021 à 16:29, Chet Ramey a écrit :
On 8/11/21 6:35 PM, Jean-Jacques Brucker wrote:
Thank a lot Chet.

I still think it would have been more consistent to extend the $'...' syntax.
Why would it be more consistent to add translation to a quoting syntax that
didn't have it than to post-process translations in a different way?

Chet


I'm probably less familiar with the history of shells and bash than you (and

others on this mailing list), but it seems to me that:

First were the chains:
  * '...' who did not expand anything
  * "..." which expanded the syntaxes $VAR and the unfortunate `...` [1]

Then the syntax $"..." was introduced, then the syntax $'...' (bash 2.X).

As the character '$' means "interprets (synonym: translates) what follows", it seems to me quite consistent that $"..." means "translates the entire following
string"

Conversely, the syntax $'...' seems to me much less consistent. (Reminder: C is
prior to shells, and bash is itself written in C).

However, the "C-string" feature is very useful (and nowadays probably more used
than the translation feature).

In absolute terms, if one day we would list all the historical design errors, dare to break some compatibilities, and manage to establish new shell standards
(I'm probably dreaming ... but do we ever know ?). Then we could have:

I would have really loved if Bash expanded translations with its built-in printf using a `-g` flag for gettext and positional arguments support instead of expanding string literal translations.

It would have allowed something like :

```sh
#!/usr/bine/env bash

# -g Gettext translation of Hello World into variable my_string
printf -v my_string -g 'Hello World!'

# Printout using gettext translated format string
printf -g 'String %1$q has %2$d characters\n' "$my_string" "${#my_string}"
```

Using this German language file:

```po
#: a.sh:4
msgid "Hello World!"
msgstr "Hallo Welt!"
#: a.sh:7
msgid "String %1$q has %2$d characters\n"
msgstr "%2$d Zeichen lang ist die Zeichenkette %1$q\n"
```

In default English, the output would be:
```none
String Hello\ World\! has 12 characters
```

In German, the output would be:
```none
11 Zeichen lang ist die Zeichenkette Hallo\ Welt\!
```


--
Léa Gris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]