android-file-transfer-linux
android-file-transfer-linux copied to clipboard
Improve macOS Locale Detection for Chinese Language Support
Summary This PR enhances the locale detection mechanism on macOS to properly support Chinese language when the application is launched from Finder. The previous implementation relied on user preference files, which has been replaced with a more robust system-based language detection approach.
Problem
On macOS, when launching the Qt application from Finder, environment variables (LANG, LC_ALL) are often not set, causing
QLocale::system() to default to en_US even when the system language is set to Chinese. This resulted in the application
displaying in English instead of the user's preferred Chinese language.
Solution Replaced the preference file-based approach with direct system language detection using macOS-specific commands:
- System Language Detection: Uses defaults command to read AppleLocale and AppleLanguages from system preferences
- Multiple Fallback Methods:
- First attempts to read AppleLocale directly
- Falls back to parsing AppleLanguages array if needed
- Converts macOS language formats to Qt-compatible locale codes
- Cross-Platform Compatibility: All macOS-specific code is wrapped in #ifdef Q_OS_MACOS to ensure Linux systems remain unaffected
Key Changes
- Removed: Dependency on ~/.android-file-transfer-locale-prefs file
- Added: System-based language detection using macOS native commands
- Enhanced: Better handling of Chinese language variants (Simplified/Traditional)
- Maintained: All existing functionality for Linux and command-line launches
Testing
- ✅ Chinese language loads correctly when launched from Finder on macOS
- ✅ Existing command-line behavior preserved
- ✅ Linux systems unaffected by macOS-specific changes
- ✅ Proper fallback to English when system language is not supported
Files Modified
- qt/main.cpp: Enhanced locale detection logic with system-based approach
Technical Details The implementation uses QProcess to execute macOS defaults commands and QRegularExpression to parse the output, converting formats like "zh-Hans-CN" to Qt's "zh_CN" format.