From bf41672f72ee3ff7679c93e0d5a8f8646c19db3e Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 17 Jun 2021 22:22:22 -0300 Subject: src/git-permalink.sh: Translate program output to pt, fr and eo The choice of implementation was very basic: Use strings in the script itself rather than relying on external tools. Compared to a compiled C program using, say, gettext.3, an sh script could also depend on it, but at runtime. An equivalent C code would require the gettext.3 dependency, but at compile time. After compilation, the code required for doing the translation is already on the binary, while an sh script would need gettext.1 to run gettext.1 commands while it executes, such as "gettext -s 'MSG_ABC'". Bash has a very appealing feature: using $"" does a lookup and translates the string. In other words, $"" runs gettext for you, without the script requiring gettext.1, just Bash. As tempting as it was, I chose not to rely on Bash. I preferred the cost of an ad-hoc solution over requiring Bash over POSIX sh. The final solution is simple enough for the git-permalink.1 program, but wouldn't scale for bigger scripts. Strings are placed together for translation, and no external tool is used for this. Due to the way that strings are now given to printf.1, ShellCheck complains a lot about those strings, alonside saying that the string translation variables are unused. They actually are used, but hidden behind an eval. Overall I'm satisfied with the solution, but I probably won't follow the same path for the manpages, and will choose something like po4a for it, instead. --- tests/cli-opts.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/cli-opts.sh') diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh index bbec933..35f2347 100755 --- a/tests/cli-opts.sh +++ b/tests/cli-opts.sh @@ -10,7 +10,7 @@ test_help_flags() { OUT="$(mktemp)" ERR="$(mktemp)" - ./git-permalink -h 1>"$OUT" 2>"$ERR" + LANG=en_US.UTF-8 ./git-permalink -h 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 0 assert_empty_stderr @@ -19,7 +19,7 @@ test_help_flags() { OUT="$(mktemp)" ERR="$(mktemp)" - ./git-permalink --help 1>"$OUT" 2>"$ERR" + LANG=en_US.UTF-8 ./git-permalink --help 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 0 assert_empty_stderr @@ -29,7 +29,7 @@ test_help_flags() { OUT="$(mktemp)" ERR="$(mktemp)" - ./git-permalink --something somethign -h 1>"$OUT" 2>"$ERR" + LANG=en_US.UTF-8 ./git-permalink --something somethign -h 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 0 assert_empty_stderr @@ -39,7 +39,7 @@ test_help_flags() { OUT="$(mktemp)" ERR="$(mktemp)" - ./git-permalink --help more things 1>"$OUT" 2>"$ERR" + LANG=en_US.UTF-8 ./git-permalink --help more things 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 0 assert_empty_stderr -- cgit v1.2.3