diff --git a/src/platform/linux.c b/src/platform/linux.c index 8ef523c87d..07a2a702bf 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -148,6 +148,34 @@ void platform_posix_sub_resolve_openrct_data_path(utf8 *out) { } } +uint8 platform_get_locale_currency(){ + char *langstring = setlocale(LC_MONETARY, ""); + + if (langstring == NULL) { + return platform_get_currency_value(NULL); + } + + struct lconv *lc = localeconv(); + + return platform_get_currency_value(lc->int_curr_symbol); +} + +uint8 platform_get_locale_measurement_format(){ + // LC_MEASUREMENT is GNU specific. + #ifdef LC_MEASUREMENT + const char *langstring = setlocale(LC_MEASUREMENT, ""); + #else + const char *langstring = setlocale(LC_ALL, ""); + #endif + + if(langstring != NULL){ + //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 MEASUREMENT_FORMAT_IMPERIAL; + } + } + return MEASUREMENT_FORMAT_METRIC; +} static void execute_cmd(char *command, int *exit_value, char *buf, size_t *buf_size) { FILE *f; diff --git a/src/platform/macos.m b/src/platform/macos.m index a21ad19d43..88b065a863 100644 --- a/src/platform/macos.m +++ b/src/platform/macos.m @@ -21,6 +21,7 @@ #include #include "platform.h" #include "../util/util.h" +#include "config.h" bool platform_check_steam_overlay_attached() { STUB(); @@ -191,4 +192,27 @@ bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer) } } +uint8 platform_get_locale_currency() +{ + @autoreleasepool + { + NSString *currencyCode = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode]; + return platform_get_currency_value(currencyCode.UTF8String); + } +} + +uint8 platform_get_locale_measurement_format() +{ + @autoreleasepool + { + NSNumber *metricSystem = [[NSLocale currentLocale] objectForKey:NSLocaleUsesMetricSystem]; + + if (metricSystem.boolValue) { + return MEASUREMENT_FORMAT_METRIC; + } + + return MEASUREMENT_FORMAT_IMPERIAL; + } +} + #endif diff --git a/src/platform/posix.c b/src/platform/posix.c index 19c2cbcb95..3de0e18013 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -863,35 +863,6 @@ time_t platform_file_get_modified_time(const utf8* path){ return 100; } -uint8 platform_get_locale_currency(){ - char *langstring = setlocale(LC_MONETARY, ""); - - if (langstring == NULL) { - return platform_get_currency_value(NULL); - } - - struct lconv *lc = localeconv(); - - return platform_get_currency_value(lc->int_curr_symbol); -} - -uint8 platform_get_locale_measurement_format(){ - // LC_MEASUREMENT is GNU specific. - #ifdef LC_MEASUREMENT - const char *langstring = setlocale(LC_MEASUREMENT, ""); - #else - const char *langstring = setlocale(LC_ALL, ""); - #endif - - if(langstring != NULL){ - //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 MEASUREMENT_FORMAT_IMPERIAL; - } - } - return MEASUREMENT_FORMAT_METRIC; -} - uint8 platform_get_locale_temperature_format(){ // LC_MEASUREMENT is GNU specific. #ifdef LC_MEASUREMENT