1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 23:04:36 +01:00

Upgrade platform_get_locale_measurement_format()

This commit is contained in:
Gymnasiast
2022-01-10 12:38:26 +01:00
parent ef77f9c2c1
commit 95717573f5
11 changed files with 64 additions and 65 deletions

View File

@@ -12,6 +12,7 @@
# include <cstring>
# include <fnmatch.h>
# include <limits.h>
# include <locale.h>
# include <pwd.h>
# include <vector>
# if defined(__FreeBSD__) || defined(__NetBSD__)
@@ -250,6 +251,26 @@ namespace Platform
return Platform::GetCurrencyValue(lc->int_curr_symbol);
}
MeasurementFormat GetLocaleMeasurementFormat()
{
// LC_MEASUREMENT is GNU specific.
# ifdef LC_MEASUREMENT
const char* langstring = setlocale(LC_MEASUREMENT, "");
# else
const char* langstring = setlocale(LC_ALL, "");
# endif
if (langstring != nullptr)
{
// using https://en.wikipedia.org/wiki/Metrication#Chronology_and_status_of_conversion_by_country as reference
if (!fnmatch("*_US*", langstring, 0) || !fnmatch("*_MM*", langstring, 0) || !fnmatch("*_LR*", langstring, 0))
{
return MeasurementFormat::Imperial;
}
}
return MeasurementFormat::Metric;
}
} // namespace Platform
#endif