diff --git a/build_tools/fish_xgettext.fish b/build_tools/fish_xgettext.fish index 12ab8d579..a46d584eb 100755 --- a/build_tools/fish_xgettext.fish +++ b/build_tools/fish_xgettext.fish @@ -15,37 +15,40 @@ begin echo "" end >$output_file -set -l tmpfile (mktemp) +set -l cargo_expanded_file (mktemp) # This is a gigantic crime. # We use cargo-expand to get all our wgettext invocations. # This might be replaced once we have a tool which properly handles macro expansions. -begin cargo expand --lib; for f in fish fish_indent fish_key_reader; cargo expand --bin $f; end; end >$tmpfile +begin + cargo expand --lib + for f in fish fish_indent fish_key_reader + cargo expand --bin $f + end +end >$cargo_expanded_file + +set -l rust_string_file (mktemp) # Extract any gettext call -set -l strs (grep -A1 wgettext_static_str <$tmpfile | - grep 'widestring::internals::core::primitive::str =' | - string match -rg '"(.*)"' | string match -rv '^%ls$|^$' | - # escaping difference between gettext and cargo-expand: single-quotes - string replace -a "\'" "'") +grep -A1 wgettext_static_str <$cargo_expanded_file | + grep 'widestring::internals::core::primitive::str =' | + string match -rg '"(.*)"' | + string match -rv '^%ls$|^$' | + # escaping difference between gettext and cargo-expand: single-quotes + string replace -a "\'" "'" >$rust_string_file # Extract any constants -set -a strs (grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile | - grep -E 'const [A-Z_]*: &str = "(.*)"' | - sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g") +grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$cargo_expanded_file | + grep -E 'const [A-Z_]*: &str = "(.*)"' | + sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g" >>$rust_string_file -rm $tmpfile +rm $cargo_expanded_file # Sort the extracted strings and remove duplicates. -# This is optional. -set -l strs (string join \n -- $strs | sort -u) +# Then, transform them into the po format +sort -u $rust_string_file | + sed -E 's/^(.*)$/msgid "\1"\nmsgstr ""\n/' >>$output_file -# We construct messages.pot ourselves instead of forcing this into msgmerge or whatever. -# The escaping so far works out okay. -for str in $strs - echo "msgid \"$str\"" - echo 'msgstr ""' - echo "" -end >>$output_file +rm $rust_string_file function extract_fish_script_messages --argument-names regex @@ -72,7 +75,9 @@ function extract_fish_script_messages --argument-names regex string unescape | string replace --all '\\' '\\\\' | string replace --all '"' '\\"' - end | sort -u | string replace --regex '^(.*)$' 'msgid "$1"'\n'msgstr ""'\n >>$output_file + end | + sort -u | + sed -E 's/^(.*)$/msgid "\1"\nmsgstr ""\n/' >>$output_file end # This regex handles explicit requests to translate a message. These are more important to translate