如何通过Bash为Chromium添加语言并启用拼写检查?
Great question! You’re absolutely right that Chromium’s command-line switches don’t include direct options for managing language preferences or spell check settings. However, since Chromium stores nearly all its user preferences in a structured JSON file, we can modify this file directly using Bash tools like jq to replicate the GUI-based "Settings > Advanced > Languages" workflow.
Here’s a step-by-step guide to do this:
1. Locate Chromium’s Preferences File
First, find the path to your Chromium user profile’s Preferences file. This varies by OS:
- Linux:
~/.config/chromium/Default/Preferences - macOS:
~/Library/Application Support/Chromium/Default/Preferences - Windows:
%LOCALAPPDATA%\Chromium\User Data\Default\Preferences(adapt commands for WSL or Git Bash if using Windows)
2. Close Chromium First
Important: Chromium overwrites the Preferences file on exit, so make sure all Chromium windows/tabs are closed before making changes.
3. Install jq (If Not Already Installed)
We’ll use jq to safely edit the JSON file without breaking its structure. Install it via your package manager:
- Debian/Ubuntu:
sudo apt install jq - macOS (Homebrew):
brew install jq - Fedora/RHEL:
sudo dnf install jq
4. Modify Preferences via Bash Script
Below is an example script that adds French (fr) as an active language, keeps English (en-US) as a secondary language, and enables spell check for both. Adjust the language codes to match your needs (e.g., es for Spanish, de for German).
Step 4.1: Backup the Preferences File
Always back up the original file before making changes:
cp ~/.config/chromium/Default/Preferences ~/.config/chromium/Default/Preferences.bak
Step 4.2: Edit the JSON Preferences
Run this jq command to update the language and spell check settings:
jq ' # Set the list of accepted languages (comma-separated) .profile.language_settings.accept_languages = "en-US,fr" | # Enable spell check for the specified dictionaries .spellcheck.dictionary = ["en-US", "fr"] | # Set the active (default) language .profile.language_settings.selected_language = "fr" | # Ensure spell check is globally enabled .spellcheck.enabled = true ' ~/.config/chromium/Default/Preferences > temp_preferences && mv temp_preferences ~/.config/chromium/Default/Preferences
Step 4.3: Fix File Permissions (If Needed)
If you run into permission issues after editing, reset the file ownership to your user:
chown $USER:$USER ~/.config/chromium/Default/Preferences
5. Verify the Changes
Launch Chromium and navigate to Settings > Advanced > Languages—you should see your specified languages listed, with the selected one set as default, and spell check enabled for both.
Notes:
- For Chromium derivatives like Google Chrome, the path will be similar (e.g.,
~/.config/google-chrome/Default/Preferenceson Linux). - Language codes follow the ISO 639-1 standard (e.g.,
pt-BRfor Brazilian Portuguese,zh-CNfor Simplified Chinese). - If you need to add more languages, simply extend the comma-separated string in
accept_languagesand the array inspellcheck.dictionary.
内容的提问来源于stack exchange,提问作者ElToro1966

