| 81 | namespace Languages { |
| 82 | |
| 83 | wxString GetSystemLanguageCode(const FilePaths &pathList) |
| 84 | { |
| 85 | wxArrayString langCodes; |
| 86 | TranslatableStrings langNames; |
| 87 | |
| 88 | GetLanguages(pathList, langCodes, langNames); |
| 89 | |
| 90 | const wxLanguageInfo *info; |
| 91 | |
| 92 | #ifdef __WXMAC__ |
| 93 | // https://github.com/audacity/audacity/issues/2493 |
| 94 | // It was observed, that macOS can have multiple `system default` languages, |
| 95 | // depending on the application rather than the user preferences. |
| 96 | // As a workaround, let's query the locale preferences for the application. |
| 97 | const wxCFStringRef appleLocale((CFStringRef)CFPreferencesCopyAppValue(CFSTR("AppleLocale"), |
| 98 | kCFPreferencesCurrentApplication)); |
| 99 | |
| 100 | const auto localeString = appleLocale.AsString(); |
| 101 | // AppleLocale has `Apple` locale format, but let us try our luck |
| 102 | // and pass it FindLanguageInfo, so we can get the best possible match. |
| 103 | info = wxLocale::FindLanguageInfo(localeString); |
| 104 | |
| 105 | if (info == nullptr) |
| 106 | { |
| 107 | // Full match has failed, lets match the language code only. |
| 108 | // wxLocale expects a two symbol code |
| 109 | wxString langCode = localeString.Left(2); |
| 110 | info = wxLocale::FindLanguageInfo(langCode); |
| 111 | } |
| 112 | #else |
| 113 | { |
| 114 | |
| 115 | const auto sysLang = wxLocale::GetSystemLanguage(); |
| 116 | info = wxLocale::GetLanguageInfo(sysLang); |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | if (info) { |
| 121 | wxString fullCode = info->CanonicalName; |
| 122 | if (fullCode.length() < 2) |
| 123 | return wxT("en"); |
| 124 | |
| 125 | wxString code = fullCode.Left(2); |
| 126 | unsigned int i; |
| 127 | |
| 128 | for(i=0; i<langCodes.size(); i++) { |
| 129 | if (langCodes[i] == fullCode) |
| 130 | return fullCode; |
| 131 | |
| 132 | if (langCodes[i] == code) |
| 133 | return code; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return wxT("en"); |
| 138 | } |
| 139 | |
| 140 | void GetLanguages( FilePaths pathList, |
no test coverage detected