Bash:向 Chromium 添加语言

Bash: Add languages to Chromium

是否可以使用 Bash 向 Chromium 添加语言?也就是说,是否相当于进入 Chromium GUI 中的设置 - 高级 - 语言,激活你想要的语言,然后激活相同语言的拼写检查?看过 this,但似乎没有符合要求的内容。

想通了。最好的方法似乎是添加一个 Python 块来使用 JSON 库读取和操作首选项文件。在你做任何事情之前,你需要在首选项文件中找到你的方位。您需要更改哪些相关元素?

如果您转到 Chromium GUI 中的首选项,您可以看到有两个相关设置:

1) 语言:

2) 词典(用于拼写检查):

这些可以在首选项文件中找到,方法是在终端中漂亮地打印文件(使用 pygmentize 改进它)或将漂亮的打印输出保存到文件中:

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

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

在文件中搜索语言设置,您会发现两个相关元素:

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

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

在你做任何其他事情之前,备份首选项文件是明智的...接下来,你可以通过将以下 python-block 添加到 bash 脚本来更改语言设置:

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

在这种情况下,脚本将从可用语言和拼写检查器中删除希腊语。请注意,为了添加语言,您需要知道 Chromium 接受的语言代码。

你可以找到更多关于阅读和写作的内容JSON here and here, and more on how to include Python scripts in bash scripts here