Index: src/OFLocalization.m ================================================================== --- src/OFLocalization.m +++ src/OFLocalization.m @@ -23,13 +23,21 @@ #import "OFArray.h" #import "OFDictionary.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" + +#if defined(OF_MORPHOS) && !defined(OF_IXEMUL) +# define BOOL EXEC_BOOL +# include +# include +# undef BOOL +#endif static OFLocalization *sharedLocalization = nil; +#if !defined(OF_MORPHOS) || defined(OF_IXEMUL) static void parseLocale(char *locale, of_string_encoding_t *encoding, OFString **language, OFString **territory) { if ((locale = of_strdup(locale)) == NULL) @@ -70,10 +78,11 @@ encoding: enc]; } @finally { free(locale); } } +#endif @implementation OFLocalization @synthesize language = _language, territory = _territory, encoding = _encoding; @synthesize decimalPoint = _decimalPoint; @@ -112,10 +121,11 @@ - init { self = [super init]; @try { +#if !defined(OF_MORPHOS) || defined(OF_IXEMUL) char *locale, *messagesLocale = NULL; _encoding = OF_STRING_ENCODING_UTF_8; _decimalPoint = @"."; _localizedStrings = [[OFMutableArray alloc] init]; @@ -123,13 +133,13 @@ if ((locale = setlocale(LC_ALL, "")) != NULL) _decimalPoint = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: _encoding]; -#ifdef LC_MESSAGES +# ifdef LC_MESSAGES messagesLocale = setlocale(LC_MESSAGES, ""); -#endif +# endif if (messagesLocale == NULL) messagesLocale = locale; if (messagesLocale != NULL) { void *pool = objc_autoreleasePoolPush(); @@ -140,10 +150,74 @@ [_language retain]; [_territory retain]; objc_autoreleasePoolPop(pool); } +#else + void *pool = objc_autoreleasePoolPush(); + char buffer[32]; + struct Locale *locale; + + /* + * Returns an empty string on MorphOS + libnix, but still + * applies it so that printf etc. work as expected. + */ + setlocale(LC_ALL, ""); + + if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { + of_string_encoding_t ASCII = OF_STRING_ENCODING_ASCII; + + @try { + _encoding = of_string_parse_encoding( + [OFString stringWithCString: buffer + encoding: ASCII]); + } @catch (OFInvalidEncodingException *e) { + _encoding = OF_STRING_ENCODING_ISO_8859_1; + } + } else + _encoding = OF_STRING_ENCODING_ISO_8859_1; + + /* + * Get it via localeconv() instead of from the Locale struct, + * to make sure we and printf etc. have the same expectations. + */ + _decimalPoint = [[OFString alloc] + initWithCString: localeconv()->decimal_point + encoding: _encoding]; + + _localizedStrings = [[OFMutableArray alloc] init]; + + if (GetVar("Language", buffer, sizeof(buffer), 0) > 0) + _language = [[OFString alloc] + initWithCString: buffer + encoding: _encoding]; + + locale = OpenLocale(NULL); + @try { + union { + uint32_t u32; + char c[4]; + } territory; + size_t length; + + territory.u32 = + OF_BSWAP32_IF_LE(locale->loc_CountryCode); + + for (length = 0; length < 4; length++) + if (territory.c[length] == 0) + break; + + _territory = [[OFString alloc] + initWithCString: territory.c + encoding: _encoding + length: length]; + } @finally { + CloseLocale(locale); + } + + objc_autoreleasePoolPop(pool); +#endif } @catch (id e) { [self release]; @throw e; } Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -88,11 +88,15 @@ } @finally { [sandbox release]; } #endif +#if !defined(OF_MORPHOS) || defined(OF_IXEMUL) [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; +#else + [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"]; +#endif if ([arguments count] < 2) help(); if ((hash = hashForName([arguments firstObject])) == nil) Index: utils/ofhash/lang/languages.json ================================================================== --- utils/ofhash/lang/languages.json +++ utils/ofhash/lang/languages.json @@ -1,8 +1,11 @@ { "de": { "": "de" + }, + "deutsch": { + "": "de" }, "german": { "": "de" } } Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -268,11 +268,15 @@ } @finally { [sandbox release]; } #endif +#if !defined(OF_MORPHOS) || defined(OF_IXEMUL) [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; +#else + [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"]; +#endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'b': Index: utils/ofhttp/lang/languages.json ================================================================== --- utils/ofhttp/lang/languages.json +++ utils/ofhttp/lang/languages.json @@ -1,8 +1,11 @@ { "de": { "": "de" + }, + "deutsch": { + "": "de" }, "german": { "": "de" } } Index: utils/ofzip/OFZIP.m ================================================================== --- utils/ofzip/OFZIP.m +++ utils/ofzip/OFZIP.m @@ -152,11 +152,15 @@ } @finally { [sandbox release]; } #endif +#if !defined(OF_MORPHOS) || defined(OF_IXEMUL) [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; +#else + [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofzip/lang"]; +#endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'f': Index: utils/ofzip/lang/languages.json ================================================================== --- utils/ofzip/lang/languages.json +++ utils/ofzip/lang/languages.json @@ -1,8 +1,11 @@ { "de": { "": "de" + }, + "deutsch": { + "": "de" }, "german": { "": "de" } }