| 512 | } |
| 513 | |
| 514 | QIcon GetFlagIconForLanguage(const QString& language_code) |
| 515 | { |
| 516 | QString actual_language_code = language_code; |
| 517 | if (language_code == QStringLiteral("system")) |
| 518 | { |
| 519 | actual_language_code = GetSystemLanguageCode(); |
| 520 | } |
| 521 | |
| 522 | QString country_code; |
| 523 | |
| 524 | const int dash_index = actual_language_code.indexOf('-'); |
| 525 | if (dash_index > 0 && dash_index < actual_language_code.length() - 1) |
| 526 | { |
| 527 | country_code = actual_language_code.mid(dash_index + 1); |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | if (actual_language_code == QStringLiteral("en")) |
| 532 | country_code = QStringLiteral("US"); |
| 533 | else |
| 534 | return QIcon(); // No flag available |
| 535 | } |
| 536 | |
| 537 | // Special cases |
| 538 | if (actual_language_code == QStringLiteral("es-419")) |
| 539 | { |
| 540 | // Latin America (es-419) use Mexico flag as representative |
| 541 | country_code = QStringLiteral("MX"); |
| 542 | } |
| 543 | else if (actual_language_code == QStringLiteral("sr-SP")) |
| 544 | { |
| 545 | // Serbia (SP) is not a valid ISO code, use RS (Serbia) |
| 546 | country_code = QStringLiteral("RS"); |
| 547 | } |
| 548 | |
| 549 | const QString flag_path = QStringLiteral("%1/icons/flags/%2.svg").arg(QtHost::GetResourcesBasePath()).arg(country_code.toLower()); |
| 550 | return QIcon(flag_path); |
| 551 | } |
| 552 | } // namespace QtUtils |
no test coverage detected