summaryrefslogtreecommitdiff
path: root/www-client/ungoogled-chromium/files/update-dicts.sh
blob: c5d600e38e75f4a65a95f30c1b0a6cc109f785da (plain)
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
#!/usr/bin/env bash

# Taken from
# https://github.com/qvint/ungoogled-chromium-fedora/commit/a68fdd679566da5134d916776f14e00c8e6a8042

self="$(readlink -f "${0}")"
self_dir="$(dirname "${self}")"
dict_utility="${self_dir}/convert_dict"

# Defaults.
hunspell_dicts_dir="/usr/share/myspell"
user_data_dir="${HOME}/.config/chromium"

# Parse command-line arguments.
while [[ $# -gt 0 ]]; do
  arg_name="${1}"

  case "${arg_name}" in
    "--hunspell-dicts-dir")
      hunspell_dicts_dir="${2}"
      shift; shift
      ;;
    "--user-data-dir")
      user_data_dir="${2}"
      shift; shift
      ;;
    *)
      echo -n "Usage: ungoogled-chromium-update-dicts "
      echo "[--hunspell-dicts-dir DIR] [--user-data-dir DIR]"
      exit 1
  esac
done

# List all chromium language entries.
chromium_language_entries="$("${dict_utility}" list)"

# Iterate through chromium language entries and make *.bdic files.
chromium_dicts_dir="${user_data_dir}/Dictionaries"
mkdir -p "${chromium_dicts_dir}"
while read -r chromium_language_entry; do
  while read \
    chromium_language \
    chromium_language_region \
    chromium_bdic_basename; do

    hunspell_language_region="${chromium_language_region//-/_}"
    aff_path="${hunspell_dicts_dir}/${hunspell_language_region}.aff"
    dic_path="${hunspell_dicts_dir}/${hunspell_language_region}.dic"
    bdic_path="${chromium_dicts_dir}/${chromium_bdic_basename}"

    if \
      [[ -f "${aff_path}" ]] && \
      [[ -f "${dic_path}" ]] && \
      [[ ! -f "${bdic_path}" ]]; then
      "${dict_utility}" convert "${aff_path}" "${dic_path}" "${bdic_path}"
    fi
  done <<< "${chromium_language_entry}"
done <<< "${chromium_language_entries}"