fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerPrepare to not localize private function descriptionsd835c5252

master
3.3 KiB80 linesraw
1# RUN: fish=%fish %fish %s
2#REQUIRES: command -v msgfmt
3#REQUIRES: %fish -c 'status buildinfo | grep localize-messages'
4
5set -l workspace_root (path resolve -- (status dirname)/../../)
6
7set -g ok true
8
9for file in $workspace_root/share/functions/*.fish
10    function error --inherit-variable workspace_root --inherit-variable file
11        echo "$(string replace $workspace_root/ '' $file):1: error: $argv"
12        set -g ok false
13    end
14    set -l basename (path basename $file)
15    set -l tier
16    set -l localize_directives (string match -r '^# localization:.*' <$file)
17    if test (count $localize_directives) -gt 1
18        error 'multiple '# localization:' directives'
19        continue
20    end
21    if set -q localize_directives[1]
22        if not set tier (string replace -rf -- \
23                '^# localization: (tier[123]|skip(?:\(\S*\))?)$' '$1' \
24                $localize_directives)
25            error 'invalid '# localization:' directive'
26            continue
27        end
28    end
29    if string match -q -- 'fish_*' $basename
30        if set -q tier[1] && test $tier != 'skip(barely-used)'
31            error "unexpected '# localization:' directive in fish_* file, those are currently implicitly tier1"
32        end
33        continue
34    end
35    if not set -q tier[1]
36        error "missing '^# localization: (tier[123]|skip)\$' directive"
37        continue
38    end
39end
40
41if $ok
42    return
43end
44
45# If the test fails, output some flight rules. Here's some rationale:
46#
47# Files named 'share/functions/fish_*' are implicitly tier1 unless overridden.
48#
49# Private functions (starting with __fish) are probably not worth bothering translators.
50# The only thing that's translated is usually the function description.
51# Most of those private functions will barely ever be seen by most users.
52# They are shown when:
53#   - typing '__fish_' TAB, but only if the function has been loaded before.
54#   - running 'type __fish_ps' or 'functions __fish_ps'.
55# The exception is if a function is directly or indirectly called by a default
56# binding; then the user might look it up with 'type __fish_list_current_token'.
57# So we use tier1 (for interesting ones) until these are un-dundered and properly documented.
58#
59# Beyond functions, completions for share/completions/<name>.fish are implicitly 'tier3',
60# unless doc_src/cmds/<name>.rst exists, in which case they are 'tier1'.  This can be overridden.
61# For common tools like coreutils, use 'tier2'.
62#
63# Wrapper functions like grep don't need translations because we use 'apropos grep'.
64
65echo "
66- Use '# localization: tier1' for
67  - user-visible functions provided by fish such as 'll'
68  - functions used in bindings like '__fish_list_current_token'
69- Use '# localization: tier2' for:
70  - rarely-used or less important functions provided by fish.
71  - completions for common tools like coreutils
72- Use '# localization: tier3'
73  - for completions that add for third-party commands, or functions that do the same
74    E.g. the ones that contain 'complete foo ... -d some-translatable-string'.
75- Use '# localization: skip(<reason>)' in function files that should not be translated.
76  - 'skip(private)' for private functions, unless they are used in bindings
77  - 'skip(uses-apropos)' for wrapper functions
78  - 'skip(deprecated)' for functions that have been superseded
79  - 'skip(barely-used)' for functions that are not documented or probably barely used
80"