1

I am using xgettext with standard input because the input is not available in a file. However, I'd like it to output a filename I specify as a comment above each string.

Current behaviour

#: Standardinput:13
msgid "User"
msgstr ""

#: Standardinput:13
msgid "Invite"
msgstr ""

#: Standardinput:14
msgid "Group"
msgstr ""

Expected behaviour

If I could set a filename to path/to/file.txt, it should output this instead:

#: path/to/file.txt:13
msgid "User"
msgstr ""

#: path/to/file.txt:13
msgid "Invite"
msgstr ""

#: path/to/file.txt:14
msgid "Group"
msgstr ""

I read every option that I can set in the docs and found nothing about it.

narrowtux
  • 664
  • 7
  • 24

1 Answers1

1

The #: path/to/file.txt:14 text is called "location" and the most control you have over this is the --no-location and --add-location flags. See xgettext.c:xgettext_open() for the source code reason why.

Meanwhile, the obvious thing to do is take your input from standard in, pipe the output to standard out, substitute manually, then store in a target PO file. Example:

xgettext -k_ -Lc -o- - < hello.c \
    | sed 's@#: standard input:@#: path/to/file.c:@g' \
    > messages.po

Obviously change the patterns inside the sed call to match your xgettext's format and the file you want to represent.

Less obvious is to symlink standard in to a file name that looks like your target. Example:

$ ln -s /dev/stdin file.c
$ echo 'int main() { printf(gettext("Hello World\n")); return 0; }' \
      | xgettext --omit-header -o- file.c
#: file.c:1
#, c-format
msgid "Hello World\n"
msgstr ""

Being able to name, for output purposes, the file when input is standard in seems like a reasonable feature. I suggest opening a request at GNU.

bishop
  • 37,830
  • 11
  • 104
  • 139
  • Yeah replacing the output is something I want to try if there is no builtin solution. I'm actually calling this from a webpack loader so I don't need to use sed but thanks for the example :) – narrowtux Jun 08 '17 at 16:13
  • 1
    Dug a little further in source and confirmed there is no CLI option. However, provided an alternative if regex substitution isn't your cup of tea. – bishop Jun 08 '17 at 16:33
  • 1
    Thanks for going through the source code for me! The symlink solution sounds like it could work a bit better in my situation since I'm also using the `--join-existing` option to have all the messages in the same .po file. Manually replacing the output afterwards would mean that I have to merge the outputs for each source file manually. I will also submit a feature request. – narrowtux Jun 08 '17 at 17:00