forked from WoeUSB/WoeUSB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-gettext-template.sh
executable file
·96 lines (90 loc) · 2.71 KB
/
build-gettext-template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Build gettext translatable messages template
#
# Copyright © 2021 WoeUSB project contributors
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Reference:
#
# * GNU gettext utilities: msginit Invocation
# https://www.gnu.org/software/gettext/manual/html_node/msginit-Invocation.html#msginit-Invocation
set \
-o errexit \
-o nounset
if test "${#}" -ne 0; then
printf \
'Usage: %s\n' \
"${0}"
exit 1
fi
declare -A dependencies=(
[coreutils]='Coreutils - GNU core utilities <https://www.gnu.org/software/coreutils/>'
[gettext]='GNU gettext <https://www.gnu.org/software/gettext/>'
[git]='Git <https://git-scm.com/>'
[sed]='GNU sed <https://www.gnu.org/software/sed/>'
)
declare -A required_commands=(
[git]="${dependencies[git]}"
[mkdir]="${dependencies[coreutils]}"
[realpath]="${dependencies[coreutils]}"
[sed]="${dependencies[sed]}"
[xgettext]="${dependencies[gettext]}"
)
dependency_check_failed=false
for required_command in "${!required_commands[@]}"; do
if ! command -v "${required_command}" >/dev/null; then
printf \
'Error: This program requires the "%s" command to be available in your command search PATHs.\n' \
"${required_command}" \
1>&2
dependency_check_failed=true
fi
done
if test "${dependency_check_failed}" == true; then
exit 2
fi
script="$(
realpath \
--strip \
"${BASH_SOURCE[0]}"
)"
script_dir="${script%/*}"
project_dir="$(
realpath \
--strip \
"${script_dir%/*}"
)"
git_describe="$(
git describe \
--always \
--dirty \
--tags
)"
project_version="${git_describe#v}"
locale_dir="${project_dir}/share/locale"
mkdir \
--parents \
--verbose \
"${locale_dir}"
template="${locale_dir}/woeusb.pot"
pushd "${project_dir}" >/dev/null
xgettext \
--copyright-holder='WoeUSB contributors <https://github.com/WoeUSB/WoeUSB/graphs/contributors>' \
--language=Shell \
--msgid-bugs-address=https://github.com/WoeUSB/WoeUSB/issues \
--output="${template}" \
--package-name=woeusb \
--package-version="${project_version}" \
./sbin/woeusb
popd >/dev/null
# False positive: Workaround "reuse._util - ERROR - Could not parse 'GPL-3.0-or-later/' \'" error
sed \
--in-place \
--expression 's/SOME DESCRIPTIVE TITLE\./GNU gettext message catalog template for WoeUSB/' \
--expression "s/Copyright (C) YEAR/Copyright (C) $(date +%Y)/" \
--expression 's/CHARSET/UTF-8/' \
--expression 's/This file is distributed under the same license as the woeusb package./SPDX''-License-Identifier: GPL-3.0-or-later/' \
"${template}"
printf \
'Info: Template generated at "%s"\n' \
"${template}"