1

Is it possibe to use Bash to add languages to Chromium? That is, do the equivalent of going to Settings - Advanced - Languages in the Chromium GUI, activate the languages you want, and then activate spell-checking for the same languages? Had a look at this, but there doesn't seem to be anything that fits the bill.

ElToro1966
  • 831
  • 1
  • 8
  • 20
  • 2
    You can use [master preferences](https://www.chromium.org/administrators/configuring-other-preferences) with "intl" and "spellcheck" objects to set up these defaults for the new users. Also try to modify Preferences file directly. – wOxxOm May 16 '18 at 11:14
  • Thanks, @wOxxOm The Preference-file contains the settigs that needs to be changed. As it is JSON, I'll try to use Python to parse and change the file. – ElToro1966 May 16 '18 at 15:21

1 Answers1

0

Figured it out. The best way seems to be to add a Python block to read and manipulate the Preferences-file using the JSON library. Before you do anything, you need to get your bearings in the Preferences-file. What are the relevant elements that you need to change?

If you go to Preferences in the Chromium GUI, you can see that there are two relevant settings:

1) Languages:

Chromium language settings

2) Dictionaries (for spell check):

Chromium spellcheck settings

These can be found in the Preferences-file by pretty-printing the file in the terminal (improving it with pygmentize) or saving a pretty-printed output to a file:

less Preferences | python -m json.tool | pygmentize -g

or

~/.config/chromium/Default$ less Preferences | python -m json.tool >> ~/Documents/output.txt

Searching through the file for language settings, you will find two relevant elements:

"intl": {
    "accept_languages": "en-US,en,nb,fr-FR,gl,de,gr,pt-PT,es-ES,sv"
},

and

"spellcheck": {
    "dictionaries": [
        "en-US",
        "nb",
        "de",
        "gr",
        "pt-PT",
        "es-ES",
        "sv"
    ],
    "dictionary": ""
}

Before you do anything else, it is wise to backup the Preferences-file... Next,you can alter the language settings by adding the following python-block to the bash script:

python - << EOF
import json
import os

data = json.load(open(os.path.expanduser("~/.config/chromium/Default/Preferences"), 'r'))
data['intl'] = {"accept_languages": "en-US,en,nb,fr-FR,gl,de,pt-PT,es-ES,sv"}
data['spellcheck'] = {"dictionaries":["en-US","nb","de","pt-PT","es-ES","sv"],"dictionary":""}
with open(os.path.expanduser('~/.config/chromium/Default/Preferences'), 'w') as outfile:
    json.dump(data, outfile)

EOF

In this case, the script will remove Greek from the available languages and the spellchecker. Note that in order to add languages, you need to know the language code accepted by Chromium.

You can find more on reading and writing JSON here and here, and more on how to include Python scripts in bash scripts here.

ElToro1966
  • 831
  • 1
  • 8
  • 20