diff --git a/build_tools/fish_xgettext.fish b/build_tools/fish_xgettext.fish index 771f25647..a3e728226 100755 --- a/build_tools/fish_xgettext.fish +++ b/build_tools/fish_xgettext.fish @@ -6,7 +6,7 @@ # works around that - based on share/functions/funced.fish. set -q TMPDIR or set -l TMPDIR /tmp -set -l tmpdir (mktemp -d $TMPDIR/fish.XXXXXX) +set tmpdir (mktemp -d $TMPDIR/fish.XXXXXX) or exit 1 # This is a gigantic crime. @@ -36,29 +36,23 @@ for str in $strs echo 'msgstr ""' end >messages.pot +function extract_fish_script_messages --argument-names name regex; + mkdir -p $tmpdir/$name/share/completions $tmpdir/$name/share/functions + for f in share/config.fish share/completions/*.fish share/functions/*.fish + string replace --filter --regex $regex '$1' <$f | string unescape \ + | string replace --all '"' '\\"' | string replace -r '(.*)' 'N_ "$1"' >$tmpdir/$name/$f + end +end + # This regex handles descriptions for `complete` and `function` statements. These messages are not # particularly important to translate. Hence the "implicit" label. set -l implicit_regex '(?:^| +)(?:complete|function).*? (?:-d|--description) (([\'"]).+?(?$tmpdir/explicit/$f - - # Handle `complete` / `function` description messages. The `| fish` is subtle. It basically - # avoids the need to use `source` with a command substitution that could affect the current - # shell. - string replace --filter --regex $implicit_regex '$1' <$f | string unescape \ - | string replace --all '"' '\\"' | string replace -r '(.*)' 'N_ "$1"' >$tmpdir/implicit/$f -end +extract_fish_script_messages explicit $explicit_regex xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot $tmpdir/{ex,im}plicit/share/*/*.fish