* Gets the current locale of the system in language-COUNTRY format. * @return Locale string. */
| 719 | * @return Locale string. |
| 720 | */ |
| 721 | std::string getLocale() |
| 722 | { |
| 723 | #ifdef _WIN32 |
| 724 | char language[9], country[9]; |
| 725 | |
| 726 | GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, language, 9); |
| 727 | GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, country, 9); |
| 728 | |
| 729 | std::ostringstream locale; |
| 730 | locale << language << "-" << country; |
| 731 | return locale.str(); |
| 732 | /* |
| 733 | wchar_t locale[LOCALE_NAME_MAX_LENGTH]; |
| 734 | LCIDToLocaleName(GetUserDefaultUILanguage(), locale, LOCALE_NAME_MAX_LENGTH, 0); |
| 735 | |
| 736 | return Language::wstrToUtf8(locale); |
| 737 | */ |
| 738 | #else |
| 739 | std::locale l(""); |
| 740 | std::string name = l.name(); |
| 741 | size_t dash = name.find_first_of('_'), dot = name.find_first_of('.'); |
| 742 | if (dot != std::string::npos) |
| 743 | { |
| 744 | name = name.substr(0, dot - 1); |
| 745 | } |
| 746 | if (dash != std::string::npos) |
| 747 | { |
| 748 | std::string language = name.substr(0, dash - 1); |
| 749 | std::string country = name.substr(dash - 1); |
| 750 | std::ostringstream locale; |
| 751 | locale << language << "-" << country; |
| 752 | return locale.str(); |
| 753 | } |
| 754 | else |
| 755 | { |
| 756 | return name + "-"; |
| 757 | } |
| 758 | #endif |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * Checks if the system's default quit shortcut was pressed. |