File: parse_json.sh

package info (click to toggle)
stellarium 25.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,307,224 kB
  • sloc: ansic: 317,377; cpp: 214,435; xml: 48,592; javascript: 26,073; python: 2,113; perl: 734; sh: 247; makefile: 192; pascal: 169
file content (30 lines) | stat: -rwxr-xr-x 1,116 bytes parent folder | download
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
#!/bin/bash
# This script parses JSON files in the current directory and extracts translatable strings.
# It generates a translations.fab file with the extracted strings.

output_file="../src/translations.fab"

# if the output file already exists, remove it
if [ -f "$output_file" ]; then
    rm "$output_file"
fi

# Write multiline comment at the beginning (overwrite the file)
cat <<EOF > "$output_file"
# This file contains translations for all translatable strings stored within data files
# which relate to Mosaic Camera Plugin.

EOF

# Loop over all JSON files
for json_file in ../resources/*.json; do
    [[ "$json_file" == "../resources/camera_order.json" ]] && continue
    jq -r '
      .[] |
      select(has("camera_name") and has("camera_description") and has("camera_url")) |
      "# TRANSLATORS: Mosaic camera name. Details at \(.camera_url)\n_(\"\(.camera_name)\")\n# TRANSLATORS: Description for mosaic camera \"\(.camera_name)\". Details at \(.camera_url)\n_(\"\(.camera_description)\")\n"
    ' "$json_file" >> "$output_file"
done

# write a new line to the output file
echo "" >> "$output_file"