Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -36,11 +36,11 @@ OFIntrospection.m \ OFInvocation.m \ OFLHAArchive.m \ OFLHAArchiveEntry.m \ OFList.m \ - OFLocalization.m \ + OFLocale.m \ OFMapTable.m \ OFMD5Hash.m \ OFMessagePackExtension.m \ OFMethodSignature.m \ OFMutableArray.m \ Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -30,11 +30,11 @@ #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFThread.h" #import "OFThread+Private.h" #import "OFSandbox.h" @@ -121,11 +121,11 @@ #ifdef OF_WINDOWS wchar_t **wargv, **wenvp; int wargc, si = 0; #endif - [[OFLocalization alloc] init]; + [[OFLocale alloc] init]; app = [[OFApplication alloc] of_init]; [app of_setArgumentCount: argc andArgumentValues: argv]; @@ -255,11 +255,11 @@ #elif defined(OF_AMIGAOS) void *pool = objc_autoreleasePoolPush(); OFFileManager *fileManager = [OFFileManager defaultManager]; OFArray *envContents = [fileManager contentsOfDirectoryAtPath: @"ENV:"]; - const of_string_encoding_t encoding = [OFLocalization encoding]; + const of_string_encoding_t encoding = [OFLocale encoding]; struct Process *proc; struct LocalVar *firstLocalVar; for (OFString *name in envContents) { void *pool2 = objc_autoreleasePoolPush(); @@ -322,11 +322,11 @@ char **env = *_NSGetEnviron(); # endif if (env != NULL) { const of_string_encoding_t encoding = - [OFLocalization encoding]; + [OFLocale encoding]; for (; *env != NULL; env++) { void *pool = objc_autoreleasePoolPush(); OFString *key, *value; char *sep; @@ -427,11 +427,11 @@ of_string_encoding_t encoding; _argc = argc; _argv = argv; - encoding = [OFLocalization encoding]; + encoding = [OFLocale encoding]; # ifndef OF_NINTENDO_DS if (*argc > 0) { # else if (__system_argv->argvMagic == ARGV_MAGIC && @@ -569,11 +569,11 @@ - (void)activateSandbox: (OFSandbox *)sandbox { # ifdef OF_HAVE_PLEDGE void *pool = objc_autoreleasePoolPush(); const char *promises = [[sandbox pledgeString] - cStringWithEncoding: [OFLocalization encoding]]; + cStringWithEncoding: [OFLocale encoding]]; OFSandbox *oldSandbox; if (pledge(promises, NULL) != 0) @throw [OFSandboxActivationFailedException exceptionWithSandbox: sandbox Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -23,11 +23,11 @@ #import "OFDNSResolver.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFDictionary.h" #import "OFFile.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFString.h" #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif @@ -63,11 +63,11 @@ if ((domain = strchr(hostname, '.')) == NULL) return nil; return [OFString stringWithCString: domain + 1 - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; } @implementation OFDNSResolver @synthesize staticHosts = _staticHosts, nameServers = _nameServers; @synthesize localDomain = _localDomain, searchDomains = _searchDomains; @@ -334,11 +334,11 @@ #ifdef OF_WINDOWS - (void)of_parseNetworkParams { void *pool = objc_autoreleasePoolPush(); - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; OFMutableArray *nameServers; OFString *localDomain; /* * We need more space than FIXED_INFO in case we have more than one * name server, but we also want it to be properly aligned, meaning we Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -28,11 +28,11 @@ #ifdef HAVE_SYS_STAT_H # include #endif #import "OFFile.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFString.h" #import "OFURL.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -222,14 +222,14 @@ # if defined(OF_WINDOWS) if ((handle = _wopen([path UTF16String], flags, _S_IREAD | _S_IWRITE)) == -1) # elif defined(OF_HAVE_OFF64_T) if ((handle = open64([path cStringWithEncoding: - [OFLocalization encoding]], flags, 0666)) == -1) + [OFLocale encoding]], flags, 0666)) == -1) # else if ((handle = open([path cStringWithEncoding: - [OFLocalization encoding]], flags, 0666)) == -1) + [OFLocale encoding]], flags, 0666)) == -1) # endif @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; @@ -242,11 +242,11 @@ if ((flags = parseMode([mode UTF8String], &handle->append)) == -1) @throw [OFInvalidArgumentException exception]; if ((handle->handle = Open([path cStringWithEncoding: - [OFLocalization encoding]], flags)) == 0) { + [OFLocale encoding]], flags)) == 0) { int errNo; switch (IoErr()) { case ERROR_OBJECT_IN_USE: case ERROR_DISK_NOT_VALIDATED: Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -30,11 +30,11 @@ #import "OFArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFFileManager.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFNumber.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURL.h" #import "OFURLHandler.h" @@ -161,11 +161,11 @@ return nil; } return [OFString stringWithCString: buffer - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #else char buffer[PATH_MAX]; if ((getcwd(buffer, PATH_MAX)) == NULL) @throw [OFGetCurrentDirectoryPathFailedException @@ -180,11 +180,11 @@ if (*tmp == '/') *tmp = '\\'; # endif return [OFString stringWithCString: buffer - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #endif } - (OFURL *)currentDirectoryURL { @@ -407,11 +407,11 @@ exceptionWithPath: path errNo: errno]; #elif defined(OF_AMIGAOS) BPTR lock, oldLock; - if ((lock = Lock([path cStringWithEncoding: [OFLocalization encoding]], + if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) { int errNo; switch (IoErr()) { case ERROR_OBJECT_IN_USE: @@ -438,11 +438,11 @@ else UnLock(oldLock); dirChanged = true; #else - if (chdir([path cStringWithEncoding: [OFLocalization encoding]]) != 0) + if (chdir([path cStringWithEncoding: [OFLocale encoding]]) != 0) @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path errNo: errno]; #endif } ADDED src/OFLocale.h Index: src/OFLocale.h ================================================================== --- src/OFLocale.h +++ src/OFLocale.h @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFObject.h" +#import "OFString.h" + +OF_ASSUME_NONNULL_BEGIN + +/*! @file */ + +/*! + * @def OF_LOCALIZED + * + * @brief Returns the localized string for the specified ID with the specified + * arguments inserted. + * + * @param ID The ID of the localized string to retrieve + * @return The localized string with the specified arguments replaced + */ +#define OF_LOCALIZED(ID, ...) \ + [[OFLocale currentLocale] localizedStringForID: ID \ + fallback: __VA_ARGS__, nil] + +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFDictionary OF_GENERIC(KeyType, ObjectType); + +/*! + * @class OFLocale OFLocale.h ObjFW/OFLocale.h + * + * @brief A class for querying the locale and retrieving localized strings. + */ +@interface OFLocale: OFObject +{ + OFString *_Nullable _language, *_Nullable _territory; + of_string_encoding_t _encoding; + OFString *_decimalPoint; + OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *) + *_localizedStrings; +} + +#ifdef OF_HAVE_CLASS_PROPERTIES +@property (class, readonly, nullable, nonatomic) OFLocale *currentLocale; +@property (class, readonly, nullable, nonatomic) OFString *language; +@property (class, readonly, nullable, nonatomic) OFString *territory; +@property (class, readonly, nonatomic) of_string_encoding_t encoding; +@property (class, readonly, nullable, nonatomic) OFString *decimalPoint; +#endif + +/*! + * @brief The language of the locale for messages. + * + * If the language is unknown, it is `nil`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *language; + +/*! + * @brief The territory of the locale for messages. + * + * If the territory is unknown, it is `nil`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *territory; + +/*! + * @brief The native 8-bit string encoding of the locale for messages. + * + * This is useful to encode strings correctly for passing them to operating + * system calls. + * + * If the native 8-bit encoding is unknown, UTF-8 is assumed. + */ +@property (readonly, nonatomic) of_string_encoding_t encoding; + +/*! + * @brief The decimal point of the system's locale. + */ +@property (readonly, nonatomic) OFString *decimalPoint; + +/*! + * @brief Returns the current OFLocale. + * + * @warning If you don't use @ref OFApplication, this might be `nil`! In this + * case, you need to manually allocate an instance and call + * @ref init once. + * + * @return The current OFLocale instance + */ ++ (nullable OFLocale *)currentLocale; + +/*! + * @brief Returns the language of the locale. + * + * If the language is unknown, `nil` is returned. + * + * @return The language of the locale. + */ ++ (nullable OFString *)language; + +/*! + * @brief Returns the territory of the locale. + * + * If the territory is unknown, `nil` is returned. + * + * @return The territory of the locale. + */ ++ (nullable OFString *)territory; + +/*! + * @brief Returns the native 8-bit string encoding for the locale. + * + * This is useful to encode strings correctly for passing them to operating + * system calls. + * + * If the native 8-bit encoding is unknown, UTF-8 is assumed. + * + * @return The native 8-bit string encoding for the locale + */ ++ (of_string_encoding_t)encoding; + +/*! + * @brief Returns the decimal point of the system's locale. + * + * @return The decimal point of the system's locale + */ ++ (nullable OFString *)decimalPoint; + +#ifdef OF_HAVE_FILES +/*! + * @brief Adds a directory to scan for language files. + * + * @param path The path to the directory to scan for language files + */ ++ (void)addLanguageDirectory: (OFString *)path; +#endif + +/*! + * @brief Initializes the current OFLocale. + * + * @warning This sets the locale via `setlocale()`! + * + * @warning You should never call this yourself, except if you do not use + * @ref OFApplication. In this case, you need to allocate exactly one + * instance of OFLocale, which will be come the current locale, and + * call this method. + */ +- (instancetype)init; + +#ifdef OF_HAVE_FILES +/*! + * @brief Adds a directory to scan for language files. + * + * @param path The path to the directory to scan for language files + */ +- (void)addLanguageDirectory: (OFString *)path; +#endif + +/*! + * @brief Returns the localized string for the specified ID, using the fallback + * string if it cannot be looked up or is missing. + * + * @note This takes a variadic argument, terminated by `nil`, that consists of + * pairs of variable names and variable values, which will be replaced + * inside the localized string. For example, you can pass + * `@"name", @"foo", nil`, causing `%[name]` to be replaced with `foo` in + * the localized string. + * + * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes + * care of the `nil` sentinel automatically. + * + * @param ID The ID for the localized string + * @param fallback The fallback to use in case the localized string cannot be + * looked up or is missing + * @return The localized string + */ +- (OFString *)localizedStringForID: (OFConstantString *)ID + fallback: (OFConstantString *)fallback, ... + OF_SENTINEL; + +/*! + * @brief Returns the localized string for the specified ID, using the fallback + * string if it cannot be looked up or is missing. + * + * @note This takes a variadic argument, terminated by `nil` and passed as + * va_list, that consists of pairs of variable names and variable values, + * which will be replaced inside the localized string. For example, you + * can pass `@"name", @"foo", nil`, causing `%[name]` to be replaced with + * `foo` in the localized string. + * + * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes + * care of the `nil` sentinel automatically. + * + * @param ID The ID for the localized string + * @param fallback The fallback to use in case the localized string cannot be + * looked up or is missing + * @param arguments A va_list of arguments, consisting of pairs of variable + * names and values to replace in the localized string, + * terminated with `nil` + * @return The localized string + */ +- (OFString *)localizedStringForID: (OFConstantString *)ID + fallback: (OFConstantString *)fallback + arguments: (va_list)arguments; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFLocale.m Index: src/OFLocale.m ================================================================== --- src/OFLocale.m +++ src/OFLocale.m @@ -0,0 +1,471 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFLocale.h" +#import "OFString.h" +#import "OFArray.h" +#import "OFDictionary.h" + +#import "OFInitializationFailedException.h" +#import "OFInvalidArgumentException.h" +#import "OFInvalidEncodingException.h" +#import "OFOpenItemFailedException.h" + +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS4 +# define __NOLIBBASE__ +# define __NOGLOBALIFACE__ +# define __USE_INLINE__ +# endif +# include +# include +# include +#endif + +static OFLocale *currentLocale = nil; + +#ifdef OF_AMIGAOS4 +extern struct ExecIFace *IExec; +static struct Library *DOSBase = NULL; +static struct DOSIFace *IDOS = NULL; +static struct Library *LocaleBase = NULL; +static struct LocaleIFace *ILocale = NULL; + +OF_DESTRUCTOR() +{ + if (ILocale != NULL) + DropInterface(ILocale); + + if (LocaleBase != NULL) + CloseLibrary(LocaleBase); + + if (IDOS != NULL) + DropInterface(IDOS); + + if (DOSBase != NULL) + CloseLibrary(DOSBase); +} +#endif + +#ifndef OF_AMIGAOS +static void +parseLocale(char *locale, of_string_encoding_t *encoding, + OFString **language, OFString **territory) +{ + if ((locale = of_strdup(locale)) == NULL) + return; + + @try { + const of_string_encoding_t enc = OF_STRING_ENCODING_ASCII; + char *tmp; + + /* We don't care for extras behind the @ */ + if ((tmp = strrchr(locale, '@')) != NULL) + *tmp = '\0'; + + /* Encoding */ + if ((tmp = strrchr(locale, '.')) != NULL) { + *tmp++ = '\0'; + + @try { + if (encoding != NULL) + *encoding = of_string_parse_encoding( + [OFString stringWithCString: tmp + encoding: enc]); + } @catch (OFInvalidEncodingException *e) { + } + } + + /* Territory */ + if ((tmp = strrchr(locale, '_')) != NULL) { + *tmp++ = '\0'; + + if (territory != NULL) + *territory = [OFString stringWithCString: tmp + encoding: enc]; + } + + if (language != NULL) + *language = [OFString stringWithCString: locale + encoding: enc]; + } @finally { + free(locale); + } +} +#endif + +@implementation OFLocale +@synthesize language = _language, territory = _territory, encoding = _encoding; +@synthesize decimalPoint = _decimalPoint; + +#ifdef OF_AMIGAOS4 ++ (void)initialize +{ + if (self != [OFLocale class]) + return; + + if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((IDOS = (struct DOSIFace *) + GetInterface(DOSBase, "main", 1, NULL)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((LocaleBase = OpenLibrary("locale.library", 38)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((ILocale = (struct LocaleIFace *) + GetInterface(LocaleBase, "main", 1, NULL)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; +} +#endif + ++ (OFLocale *)currentLocale +{ + return currentLocale; +} + ++ (OFString *)language +{ + return [currentLocale language]; +} + ++ (OFString *)territory +{ + return [currentLocale territory]; +} + ++ (of_string_encoding_t)encoding +{ + return [currentLocale encoding]; +} + ++ (OFString *)decimalPoint +{ + return [currentLocale decimalPoint]; +} + +#ifdef OF_HAVE_FILES ++ (void)addLanguageDirectory: (OFString *)path +{ + [currentLocale addLanguageDirectory: path]; +} +#endif + +- (instancetype)init +{ + self = [super init]; + + @try { +#ifndef OF_AMIGAOS + char *locale, *messagesLocale = NULL; + + if (currentLocale != nil) + @throw [OFInitializationFailedException + exceptionWithClass: [OFLocale class]]; + + _encoding = OF_STRING_ENCODING_UTF_8; + _decimalPoint = @"."; + _localizedStrings = [[OFMutableArray alloc] init]; + + if ((locale = setlocale(LC_ALL, "")) != NULL) + _decimalPoint = [[OFString alloc] + initWithCString: localeconv()->decimal_point + encoding: _encoding]; + +# ifdef LC_MESSAGES + messagesLocale = setlocale(LC_MESSAGES, ""); +# endif + if (messagesLocale == NULL) + messagesLocale = locale; + + if (messagesLocale != NULL) { + void *pool = objc_autoreleasePoolPush(); + + parseLocale(messagesLocale, &_encoding, + &_language, &_territory); + + [_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 defined(OF_MORPHOS) + if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { +# elif defined(OF_AMIGAOS4) + if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { +# else + if (0) { +# endif + 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]; + + if ((locale = OpenLocale(NULL)) != 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; + } + + currentLocale = self; + + return self; +} + +- (void)dealloc +{ + [_language release]; + [_territory release]; + [_decimalPoint release]; + [_localizedStrings release]; + + [super dealloc]; +} + +#ifdef OF_HAVE_FILES +- (void)addLanguageDirectory: (OFString *)path +{ + void *pool; + OFString *mapPath, *language, *territory, *languageFile; + OFDictionary *map; + + if (_language == nil) + return; + + pool = objc_autoreleasePoolPush(); + + mapPath = [path stringByAppendingPathComponent: @"languages.json"]; + @try { + map = [[OFString stringWithContentsOfFile: mapPath] JSONValue]; + } @catch (OFOpenItemFailedException *e) { + objc_autoreleasePoolPop(pool); + return; + } + + language = [_language lowercaseString]; + territory = [_territory lowercaseString]; + + if (territory == nil) + territory = @""; + + languageFile = [[map objectForKey: language] objectForKey: territory]; + if (languageFile == nil) + languageFile = [[map objectForKey: language] + objectForKey: @""]; + + if (languageFile == nil) { + objc_autoreleasePoolPop(pool); + return; + } + + languageFile = [path stringByAppendingPathComponent: + [languageFile stringByAppendingString: @".json"]]; + + [_localizedStrings addObject: + [[OFString stringWithContentsOfFile: languageFile] JSONValue]]; + + objc_autoreleasePoolPop(pool); +} +#endif + +- (OFString *)localizedStringForID: (OFConstantString *)ID + fallback: (OFConstantString *)fallback, ... +{ + OFString *ret; + va_list args; + + va_start(args, fallback); + ret = [self localizedStringForID: ID + fallback: fallback + arguments: args]; + va_end(args); + + return ret; +} + +- (OFString *)localizedStringForID: (OFConstantString *)ID + fallback: (OFConstantString *)fallback + arguments: (va_list)arguments +{ + OFMutableString *ret = [OFMutableString string]; + void *pool = objc_autoreleasePoolPush(); + const char *UTF8String = NULL; + size_t last, UTF8StringLength; + int state = 0; + + for (OFDictionary *strings in _localizedStrings) { + id string = [strings objectForKey: ID]; + + if (string == nil) + continue; + + if ([string isKindOfClass: [OFArray class]]) + string = [string componentsJoinedByString: @""]; + + UTF8String = [string UTF8String]; + UTF8StringLength = [string UTF8StringLength]; + break; + } + + if (UTF8String == NULL) { + UTF8String = [fallback UTF8String]; + UTF8StringLength = [fallback UTF8StringLength]; + } + + state = 0; + last = 0; + for (size_t i = 0; i < UTF8StringLength; i++) { + switch (state) { + case 0: + if (UTF8String[i] == '%') { + [ret appendUTF8String: UTF8String + last + length: i - last]; + + last = i + 1; + state = 1; + } + break; + case 1: + if (UTF8String[i] == '[') { + last = i + 1; + state = 2; + } else { + [ret appendString: @"%"]; + state = 0; + } + break; + case 2: + if (UTF8String[i] == ']') { + va_list argsCopy; + OFConstantString *name; + + OFString *var = [OFString + stringWithUTF8String: UTF8String + last + length: i - last]; + + /* + * We loop, as most of the time, we only have + * one or maybe two variables, meaning looping + * is faster than constructing a dictionary. + */ + va_copy(argsCopy, arguments); + while ((name = va_arg(argsCopy, + OFConstantString *)) != nil) { + id value = va_arg(argsCopy, id); + + if (value == nil) + @throw + [OFInvalidArgumentException + exception]; + + if ([name isEqual: var]) { + [ret appendString: + [value description]]; + break; + } + } + + last = i + 1; + state = 0; + } + break; + } + } + switch (state) { + case 1: + [ret appendString: @"%"]; + /* Explicit fall-through */ + case 0: + [ret appendUTF8String: UTF8String + last + length: UTF8StringLength - last]; + break; + } + + objc_autoreleasePoolPop(pool); + + [ret makeImmutable]; + + return ret; +} +@end DELETED src/OFLocalization.h Index: src/OFLocalization.h ================================================================== --- src/OFLocalization.h +++ src/OFLocalization.h @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFObject.h" -#import "OFString.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! @file */ - -/*! - * @def OF_LOCALIZED - * - * @brief Returns the localized string for the specified ID with the specified - * arguments inserted. - * - * @param ID The ID of the localized string to retrieve - * @return The localized string with the specified arguments replaced - */ -#define OF_LOCALIZED(ID, ...) \ - [[OFLocalization sharedLocalization] \ - localizedStringForID: ID \ - fallback: __VA_ARGS__, nil] - -@class OFMutableArray OF_GENERIC(ObjectType); -@class OFDictionary OF_GENERIC(KeyType, ObjectType); - -/*! - * @class OFLocalization OFLocalization.h ObjFW/OFLocalization.h - * - * @brief A class for querying the locale and retrieving localized strings. - */ -@interface OFLocalization: OFObject -{ - OFString *_Nullable _language, *_Nullable _territory; - of_string_encoding_t _encoding; - OFString *_decimalPoint; - OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *) - *_localizedStrings; -} - -#ifdef OF_HAVE_CLASS_PROPERTIES -@property (class, readonly, nullable, nonatomic) - OFLocalization *sharedLocalization; -@property (class, readonly, nullable, nonatomic) OFString *language; -@property (class, readonly, nullable, nonatomic) OFString *territory; -@property (class, readonly, nonatomic) of_string_encoding_t encoding; -@property (class, readonly, nullable, nonatomic) OFString *decimalPoint; -#endif - -/*! - * @brief The language of the locale for messages. - * - * If the language is unknown, it is `nil`. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *language; - -/*! - * @brief The territory of the locale for messages. - * - * If the territory is unknown, it is `nil`. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *territory; - -/*! - * @brief The native 8-bit string encoding of the locale for messages. - * - * This is useful to encode strings correctly for passing them to operating - * system calls. - * - * If the native 8-bit encoding is unknown, UTF-8 is assumed. - */ -@property (readonly, nonatomic) of_string_encoding_t encoding; - -/*! - * @brief The decimal point of the system's locale. - */ -@property (readonly, nonatomic) OFString *decimalPoint; - -/*! - * @brief Returns the shared OFLocalization instance. - * - * @warning If you don't use @ref OFApplication, this might be `nil`! In this - * case, you need to manually allocate an instance and call - * @ref init once. - * - * @return The shared OFLocalization instance - */ -+ (nullable OFLocalization *)sharedLocalization; - -/*! - * @brief Returns the language of the locale. - * - * If the language is unknown, `nil` is returned. - * - * @return The language of the locale. - */ -+ (nullable OFString *)language; - -/*! - * @brief Returns the territory of the locale. - * - * If the territory is unknown, `nil` is returned. - * - * @return The territory of the locale. - */ -+ (nullable OFString *)territory; - -/*! - * @brief Returns the native 8-bit string encoding for the locale. - * - * This is useful to encode strings correctly for passing them to operating - * system calls. - * - * If the native 8-bit encoding is unknown, UTF-8 is assumed. - * - * @return The native 8-bit string encoding for the locale - */ -+ (of_string_encoding_t)encoding; - -/*! - * @brief Returns the decimal point of the system's locale. - * - * @return The decimal point of the system's locale - */ -+ (nullable OFString *)decimalPoint; - -#ifdef OF_HAVE_FILES -/*! - * @brief Adds a directory to scan for language files. - * - * @param path The path to the directory to scan for language files - */ -+ (void)addLanguageDirectory: (OFString *)path; -#endif - -/*! - * @brief Initializes the OFLocalization singleton with the specified locale. - * - * @warning This sets the locale via `setlocale()`! - * - * @warning You should never call this yourself, except if you do not use - * @ref OFApplication. In this case, you need to allocate exactly one - * instance of OFLocalization, which will be come the singleton, and - * call this method. - */ -- (instancetype)init; - -#ifdef OF_HAVE_FILES -/*! - * @brief Adds a directory to scan for language files. - * - * @param path The path to the directory to scan for language files - */ -- (void)addLanguageDirectory: (OFString *)path; -#endif - -/*! - * @brief Returns the localized string for the specified ID, using the fallback - * string if it cannot be looked up or is missing. - * - * @note This takes a variadic argument, terminated by `nil`, that consists of - * pairs of variable names and variable values, which will be replaced - * inside the localized string. For example, you can pass - * `@"name", @"foo", nil`, causing `%[name]` to be replaced with `foo` in - * the localized string. - * - * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes - * care of the `nil` sentinel automatically. - * - * @param ID The ID for the localized string - * @param fallback The fallback to use in case the localized string cannot be - * looked up or is missing - * @return The localized string - */ -- (OFString *)localizedStringForID: (OFConstantString *)ID - fallback: (OFConstantString *)fallback, ... - OF_SENTINEL; - -/*! - * @brief Returns the localized string for the specified ID, using the fallback - * string if it cannot be looked up or is missing. - * - * @note This takes a variadic argument, terminated by `nil` and passed as - * va_list, that consists of pairs of variable names and variable values, - * which will be replaced inside the localized string. For example, you - * can pass `@"name", @"foo", nil`, causing `%[name]` to be replaced with - * `foo` in the localized string. - * - * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes - * care of the `nil` sentinel automatically. - * - * @param ID The ID for the localized string - * @param fallback The fallback to use in case the localized string cannot be - * looked up or is missing - * @param arguments A va_list of arguments, consisting of pairs of variable - * names and values to replace in the localized string, - * terminated with `nil` - * @return The localized string - */ -- (OFString *)localizedStringForID: (OFConstantString *)ID - fallback: (OFConstantString *)fallback - arguments: (va_list)arguments; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFLocalization.m Index: src/OFLocalization.m ================================================================== --- src/OFLocalization.m +++ src/OFLocalization.m @@ -1,471 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "OFLocalization.h" -#import "OFString.h" -#import "OFArray.h" -#import "OFDictionary.h" - -#import "OFInitializationFailedException.h" -#import "OFInvalidArgumentException.h" -#import "OFInvalidEncodingException.h" -#import "OFOpenItemFailedException.h" - -#ifdef OF_AMIGAOS -# ifdef OF_AMIGAOS4 -# define __NOLIBBASE__ -# define __NOGLOBALIFACE__ -# define __USE_INLINE__ -# endif -# include -# include -# include -#endif - -static OFLocalization *sharedLocalization = nil; - -#ifdef OF_AMIGAOS4 -extern struct ExecIFace *IExec; -static struct Library *DOSBase = NULL; -static struct DOSIFace *IDOS = NULL; -static struct Library *LocaleBase = NULL; -static struct LocaleIFace *ILocale = NULL; - -OF_DESTRUCTOR() -{ - if (ILocale != NULL) - DropInterface(ILocale); - - if (LocaleBase != NULL) - CloseLibrary(LocaleBase); - - if (IDOS != NULL) - DropInterface(IDOS); - - if (DOSBase != NULL) - CloseLibrary(DOSBase); -} -#endif - -#ifndef OF_AMIGAOS -static void -parseLocale(char *locale, of_string_encoding_t *encoding, - OFString **language, OFString **territory) -{ - if ((locale = of_strdup(locale)) == NULL) - return; - - @try { - const of_string_encoding_t enc = OF_STRING_ENCODING_ASCII; - char *tmp; - - /* We don't care for extras behind the @ */ - if ((tmp = strrchr(locale, '@')) != NULL) - *tmp = '\0'; - - /* Encoding */ - if ((tmp = strrchr(locale, '.')) != NULL) { - *tmp++ = '\0'; - - @try { - if (encoding != NULL) - *encoding = of_string_parse_encoding( - [OFString stringWithCString: tmp - encoding: enc]); - } @catch (OFInvalidEncodingException *e) { - } - } - - /* Territory */ - if ((tmp = strrchr(locale, '_')) != NULL) { - *tmp++ = '\0'; - - if (territory != NULL) - *territory = [OFString stringWithCString: tmp - encoding: enc]; - } - - if (language != NULL) - *language = [OFString stringWithCString: locale - encoding: enc]; - } @finally { - free(locale); - } -} -#endif - -@implementation OFLocalization -@synthesize language = _language, territory = _territory, encoding = _encoding; -@synthesize decimalPoint = _decimalPoint; - -#ifdef OF_AMIGAOS4 -+ (void)initialize -{ - if (self != [OFLocalization class]) - return; - - if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL) - @throw [OFInitializationFailedException - exceptionWithClass: self]; - - if ((IDOS = (struct DOSIFace *) - GetInterface(DOSBase, "main", 1, NULL)) == NULL) - @throw [OFInitializationFailedException - exceptionWithClass: self]; - - if ((LocaleBase = OpenLibrary("locale.library", 38)) == NULL) - @throw [OFInitializationFailedException - exceptionWithClass: self]; - - if ((ILocale = (struct LocaleIFace *) - GetInterface(LocaleBase, "main", 1, NULL)) == NULL) - @throw [OFInitializationFailedException - exceptionWithClass: self]; -} -#endif - -+ (OFLocalization *)sharedLocalization -{ - return sharedLocalization; -} - -+ (OFString *)language -{ - return [sharedLocalization language]; -} - -+ (OFString *)territory -{ - return [sharedLocalization territory]; -} - -+ (of_string_encoding_t)encoding -{ - return [sharedLocalization encoding]; -} - -+ (OFString *)decimalPoint -{ - return [sharedLocalization decimalPoint]; -} - -#ifdef OF_HAVE_FILES -+ (void)addLanguageDirectory: (OFString *)path -{ - [sharedLocalization addLanguageDirectory: path]; -} -#endif - -- (instancetype)init -{ - self = [super init]; - - @try { -#ifndef OF_AMIGAOS - char *locale, *messagesLocale = NULL; - - if (sharedLocalization != nil) - @throw [OFInitializationFailedException - exceptionWithClass: [OFLocalization class]]; - - _encoding = OF_STRING_ENCODING_UTF_8; - _decimalPoint = @"."; - _localizedStrings = [[OFMutableArray alloc] init]; - - if ((locale = setlocale(LC_ALL, "")) != NULL) - _decimalPoint = [[OFString alloc] - initWithCString: localeconv()->decimal_point - encoding: _encoding]; - -# ifdef LC_MESSAGES - messagesLocale = setlocale(LC_MESSAGES, ""); -# endif - if (messagesLocale == NULL) - messagesLocale = locale; - - if (messagesLocale != NULL) { - void *pool = objc_autoreleasePoolPush(); - - parseLocale(messagesLocale, &_encoding, - &_language, &_territory); - - [_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 defined(OF_MORPHOS) - if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { -# elif defined(OF_AMIGAOS4) - if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { -# else - if (0) { -# endif - 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]; - - if ((locale = OpenLocale(NULL)) != 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; - } - - sharedLocalization = self; - - return self; -} - -- (void)dealloc -{ - [_language release]; - [_territory release]; - [_decimalPoint release]; - [_localizedStrings release]; - - [super dealloc]; -} - -#ifdef OF_HAVE_FILES -- (void)addLanguageDirectory: (OFString *)path -{ - void *pool; - OFString *mapPath, *language, *territory, *languageFile; - OFDictionary *map; - - if (_language == nil) - return; - - pool = objc_autoreleasePoolPush(); - - mapPath = [path stringByAppendingPathComponent: @"languages.json"]; - @try { - map = [[OFString stringWithContentsOfFile: mapPath] JSONValue]; - } @catch (OFOpenItemFailedException *e) { - objc_autoreleasePoolPop(pool); - return; - } - - language = [_language lowercaseString]; - territory = [_territory lowercaseString]; - - if (territory == nil) - territory = @""; - - languageFile = [[map objectForKey: language] objectForKey: territory]; - if (languageFile == nil) - languageFile = [[map objectForKey: language] - objectForKey: @""]; - - if (languageFile == nil) { - objc_autoreleasePoolPop(pool); - return; - } - - languageFile = [path stringByAppendingPathComponent: - [languageFile stringByAppendingString: @".json"]]; - - [_localizedStrings addObject: - [[OFString stringWithContentsOfFile: languageFile] JSONValue]]; - - objc_autoreleasePoolPop(pool); -} -#endif - -- (OFString *)localizedStringForID: (OFConstantString *)ID - fallback: (OFConstantString *)fallback, ... -{ - OFString *ret; - va_list args; - - va_start(args, fallback); - ret = [self localizedStringForID: ID - fallback: fallback - arguments: args]; - va_end(args); - - return ret; -} - -- (OFString *)localizedStringForID: (OFConstantString *)ID - fallback: (OFConstantString *)fallback - arguments: (va_list)arguments -{ - OFMutableString *ret = [OFMutableString string]; - void *pool = objc_autoreleasePoolPush(); - const char *UTF8String = NULL; - size_t last, UTF8StringLength; - int state = 0; - - for (OFDictionary *strings in _localizedStrings) { - id string = [strings objectForKey: ID]; - - if (string == nil) - continue; - - if ([string isKindOfClass: [OFArray class]]) - string = [string componentsJoinedByString: @""]; - - UTF8String = [string UTF8String]; - UTF8StringLength = [string UTF8StringLength]; - break; - } - - if (UTF8String == NULL) { - UTF8String = [fallback UTF8String]; - UTF8StringLength = [fallback UTF8StringLength]; - } - - state = 0; - last = 0; - for (size_t i = 0; i < UTF8StringLength; i++) { - switch (state) { - case 0: - if (UTF8String[i] == '%') { - [ret appendUTF8String: UTF8String + last - length: i - last]; - - last = i + 1; - state = 1; - } - break; - case 1: - if (UTF8String[i] == '[') { - last = i + 1; - state = 2; - } else { - [ret appendString: @"%"]; - state = 0; - } - break; - case 2: - if (UTF8String[i] == ']') { - va_list argsCopy; - OFConstantString *name; - - OFString *var = [OFString - stringWithUTF8String: UTF8String + last - length: i - last]; - - /* - * We loop, as most of the time, we only have - * one or maybe two variables, meaning looping - * is faster than constructing a dictionary. - */ - va_copy(argsCopy, arguments); - while ((name = va_arg(argsCopy, - OFConstantString *)) != nil) { - id value = va_arg(argsCopy, id); - - if (value == nil) - @throw - [OFInvalidArgumentException - exception]; - - if ([name isEqual: var]) { - [ret appendString: - [value description]]; - break; - } - } - - last = i + 1; - state = 0; - } - break; - } - } - switch (state) { - case 1: - [ret appendString: @"%"]; - /* Explicit fall-through */ - case 0: - [ret appendUTF8String: UTF8String + last - length: UTF8StringLength - last]; - break; - } - - objc_autoreleasePoolPop(pool); - - [ret makeImmutable]; - - return ret; -} -@end Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -27,11 +27,11 @@ # include #endif #import "OFObject.h" #import "OFArray.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFMethodSignature.h" #import "OFRunLoop.h" #import "OFThread.h" #import "OFTimer.h" @@ -117,11 +117,11 @@ static void uncaughtExceptionHandler(id exception) { OFString *description = [exception description]; OFArray *backtrace = nil; - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", [description cStringWithEncoding: encoding]); if ([exception respondsToSelector: @selector(backtrace)]) @@ -210,12 +210,11 @@ } const char * _NSPrintForDebugger(id object) { - return [[object description] - cStringWithEncoding: [OFLocalization encoding]]; + return [[object description] cStringWithEncoding: [OFLocale encoding]]; } /* References for static linking */ void _references_to_categories_of_OFObject(void) Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -24,11 +24,11 @@ # include #endif #import "OFPlugin.h" #import "OFString.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFInitializationFailedException.h" #import "OFLoadPluginFailedException.h" typedef OFPlugin *(*init_plugin_t)(void); @@ -35,12 +35,11 @@ of_plugin_handle_t of_dlopen(OFString *path, int flags) { #ifndef OF_WINDOWS - return dlopen([path cStringWithEncoding: [OFLocalization encoding]], - flags); + return dlopen([path cStringWithEncoding: [OFLocale encoding]], flags); #else if (path == nil) return GetModuleHandle(NULL); return LoadLibraryW([path UTF16String]); @@ -70,11 +69,11 @@ OFString * of_dlerror(void) { #ifndef OF_WINDOWS return [OFString stringWithCString: dlerror() - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #else return nil; #endif } Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -34,11 +34,11 @@ #import "OFProcess.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFData.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" @@ -143,11 +143,11 @@ if (pipe(_readPipe) != 0 || pipe(_writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - path = [program cStringWithEncoding: [OFLocalization encoding]]; + path = [program cStringWithEncoding: [OFLocale encoding]]; [self of_getArgv: &argv forProgramName: programName andArguments: arguments]; @try { @@ -343,11 +343,11 @@ of_string_encoding_t encoding; *argv = [self allocMemoryWithSize: sizeof(char *) count: count + 2]; - encoding = [OFLocalization encoding]; + encoding = [OFLocale encoding]; (*argv)[0] = (char *)[programName cStringWithEncoding: encoding]; for (i = 0; i < count; i++) (*argv)[i + 1] = @@ -364,11 +364,11 @@ of_string_encoding_t encoding; if (environment == nil) return NULL; - encoding = [OFLocalization encoding]; + encoding = [OFLocale encoding]; count = [environment count]; envp = [self allocMemoryWithSize: sizeof(char *) count: count + 1]; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -57,12 +57,12 @@ /*! * @brief The encoding of a string. */ typedef enum of_string_encoding_t { /* - * UTF-8 *has* to be 0, so that if the @ref OFLocalization singleton is - * `nil`, `[OFLocalization encoding]` returns UTF-8. + * UTF-8 *has* to be 0, so that if the current @ref OFLocale is + * `nil`, `[OFLocale encoding]` returns UTF-8. */ /*! UTF-8 */ OF_STRING_ENCODING_UTF_8, /*! ASCII */ OF_STRING_ENCODING_ASCII, Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -35,11 +35,11 @@ #import "OFString_UTF8+Private.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" -#import "OFLocalization.h" +#import "OFLocale.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFURL.h" @@ -2569,11 +2569,11 @@ #else /* * If we have no strtof_l, we have no other choice but to replace "." * with the locale's decimal point. */ - OFString *decimalPoint = [OFLocalization decimalPoint]; + OFString *decimalPoint = [OFLocale decimalPoint]; const char *UTF8String = [[self stringByReplacingOccurrencesOfString: @"." withString: decimalPoint] UTF8String]; #endif char *endPointer = NULL; @@ -2619,11 +2619,11 @@ #else /* * If we have no strtod_l, we have no other choice but to replace "." * with the locale's decimal point. */ - OFString *decimalPoint = [OFLocalization decimalPoint]; + OFString *decimalPoint = [OFLocale decimalPoint]; const char *UTF8String = [[self stringByReplacingOccurrencesOfString: @"." withString: decimalPoint] UTF8String]; #endif char *endPointer = NULL; Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -39,11 +39,11 @@ #import "OFSystemInfo.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDictionary.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFString.h" #import "OFNotImplementedException.h" #ifdef OF_HAVE_THREADS @@ -135,11 +135,11 @@ if (uname(&utsname) != 0) return; operatingSystemName = [[OFString alloc] initWithCString: utsname.sysname - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #endif } static void initOperatingSystemVersion(void) @@ -228,11 +228,11 @@ if (uname(&utsname) != 0) return; operatingSystemVersion = [[OFString alloc] initWithCString: utsname.release - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #endif } #if defined(OF_X86_64) || defined(OF_X86) static OF_INLINE struct x86_regs OF_CONST_FUNC Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -51,11 +51,11 @@ #import "OFAutoreleasePool+Private.h" #import "OFAutoreleasePool.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFList.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFRunLoop.h" #import "OFString.h" #ifdef OF_WINDOWS # include @@ -104,11 +104,11 @@ thread->_pool = objc_autoreleasePoolPush(); name = [thread name]; if (name != nil) of_thread_set_name( - [name cStringWithEncoding: [OFLocalization encoding]]); + [name cStringWithEncoding: [OFLocale encoding]]); else of_thread_set_name(object_getClassName(thread)); /* * Nasty workaround for thread implementations which can't return a @@ -285,11 +285,11 @@ { [[OFThread currentThread] setName: name]; if (name != nil) of_thread_set_name( - [name cStringWithEncoding: [OFLocalization encoding]]); + [name cStringWithEncoding: [OFLocale encoding]]); else of_thread_set_name(class_getName([self class])); } + (OFString *)name Index: src/OFURLHandler_file.m ================================================================== --- src/OFURLHandler_file.m +++ src/OFURLHandler_file.m @@ -37,11 +37,11 @@ #import "OFURLHandler_file.h" #import "OFArray.h" #import "OFDate.h" #import "OFFile.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFNumber.h" #import "OFURL.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" @@ -109,11 +109,11 @@ BPTR lock; struct FileInfoBlock fib; of_time_interval_t timeInterval; struct Locale *locale; - if ((lock = Lock([path cStringWithEncoding: [OFLocalization encoding]], + if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) { switch (IoErr()) { case ERROR_OBJECT_IN_USE: case ERROR_DISK_NOT_VALIDATED: errno = EBUSY; @@ -167,28 +167,24 @@ buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval; return 0; #elif defined(OF_HAVE_OFF64_T) - return stat64([path cStringWithEncoding: [OFLocalization encoding]], - buffer); + return stat64([path cStringWithEncoding: [OFLocale encoding]], buffer); #else - return stat([path cStringWithEncoding: [OFLocalization encoding]], - buffer); + return stat([path cStringWithEncoding: [OFLocale encoding]], buffer); #endif } static int of_lstat(OFString *path, of_stat_t *buffer) { #if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) # ifdef OF_HAVE_OFF64_T - return lstat64([path cStringWithEncoding: [OFLocalization encoding]], - buffer); + return lstat64([path cStringWithEncoding: [OFLocale encoding]], buffer); # else - return lstat([path cStringWithEncoding: [OFLocalization encoding]], - buffer); + return lstat([path cStringWithEncoding: [OFLocale encoding]], buffer); # endif #else return of_stat(path, buffer); #endif } @@ -256,11 +252,11 @@ # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; struct passwd *passwd = getpwuid(s->st_uid); struct group *group_ = getgrgid(s->st_gid); if (passwd != NULL) { OFString *owner = [OFString @@ -294,11 +290,11 @@ #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS OFString *path = [URL fileSystemRepresentation]; # ifndef OF_WINDOWS if (S_ISLNK(s->st_mode)) { - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; char destinationC[PATH_MAX]; ssize_t length; OFString *destination; of_file_attribute_key_t key; @@ -481,12 +477,11 @@ #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS uint16_t mode = [permissions uInt16Value] & 0777; OFString *path = [URL fileSystemRepresentation]; # ifndef OF_WINDOWS - if (chmod([path cStringWithEncoding: [OFLocalization encoding]], - mode) != 0) + if (chmod([path cStringWithEncoding: [OFLocale encoding]], mode) != 0) # else if (_wchmod([path UTF16String], mode) != 0) # endif @throw [OFSetItemAttributesFailedException exceptionWithURL: URL @@ -511,11 +506,11 @@ of_string_encoding_t encoding; if (owner == nil && group == nil) @throw [OFInvalidArgumentException exception]; - encoding = [OFLocalization encoding]; + encoding = [OFLocale encoding]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif @@ -670,11 +665,11 @@ errNo: errno]; #elif defined(OF_AMIGAOS) BPTR lock; if ((lock = CreateDir( - [path cStringWithEncoding: [OFLocalization encoding]])) == 0) { + [path cStringWithEncoding: [OFLocale encoding]])) == 0) { int errNo; switch (IoErr()) { case ERROR_NO_FREE_STORE: case ERROR_DISK_FULL: @@ -703,12 +698,11 @@ errNo: errNo]; } UnLock(lock); #else - if (mkdir([path cStringWithEncoding: [OFLocalization encoding]], - 0777) != 0) + if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0) @throw [OFCreateDirectoryFailedException exceptionWithURL: URL errNo: errno]; #endif @@ -769,11 +763,11 @@ errNo: EIO]; } @finally { FindClose(handle); } #elif defined(OF_AMIGAOS) - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; BPTR lock; struct FileInfoBlock fib; if ((lock = Lock([path cStringWithEncoding: encoding], SHARED_LOCK)) == 0) { @@ -824,11 +818,11 @@ errNo: EIO]; } @finally { UnLock(lock); } #else - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; DIR *dir; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil @@ -948,22 +942,21 @@ objc_autoreleasePoolPop(pool2); } #ifndef OF_AMIGAOS # ifndef OF_WINDOWS - if (rmdir([path cStringWithEncoding: - [OFLocalization encoding]]) != 0) + if (rmdir([path cStringWithEncoding: [OFLocale encoding]]) != 0) # else if (_wrmdir([path UTF16String]) != 0) # endif @throw [OFRemoveItemFailedException exceptionWithURL: URL errNo: errno]; } else { # ifndef OF_WINDOWS if (unlink([path cStringWithEncoding: - [OFLocalization encoding]]) != 0) + [OFLocale encoding]]) != 0) # else if (_wunlink([path UTF16String]) != 0) # endif @throw [OFRemoveItemFailedException exceptionWithURL: URL @@ -970,12 +963,11 @@ errNo: errno]; #endif } #ifdef OF_AMIGAOS - if (!DeleteFile( - [path cStringWithEncoding: [OFLocalization encoding]])) { + if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]])) { int errNo; switch (IoErr()) { case ERROR_OBJECT_IN_USE: case ERROR_DISK_NOT_VALIDATED: @@ -1019,11 +1011,11 @@ sourcePath = [source fileSystemRepresentation]; destinationPath = [destination fileSystemRepresentation]; # ifndef OF_WINDOWS - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; if (link([sourcePath cStringWithEncoding: encoding], [destinationPath cStringWithEncoding: encoding]) != 0) @throw [OFLinkFailedException exceptionWithSourceURL: source @@ -1056,11 +1048,11 @@ @throw [OFInvalidArgumentException exception]; path = [URL fileSystemRepresentation]; # ifndef OF_WINDOWS - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; if (symlink([target cStringWithEncoding: encoding], [path cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithURL: URL @@ -1106,11 +1098,11 @@ @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: errno]; #elif defined(OF_AMIGAOS) - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; if (!Rename([[source fileSystemRepresentation] cStringWithEncoding: encoding], [[destination fileSystemRepresentation] cStringWithEncoding: encoding])) { @@ -1142,11 +1134,11 @@ exceptionWithSourceURL: source destinationURL: destination errNo: errNo]; } #else - of_string_encoding_t encoding = [OFLocalization encoding]; + of_string_encoding_t encoding = [OFLocale encoding]; if (rename([[source fileSystemRepresentation] cStringWithEncoding: encoding], [[destination fileSystemRepresentation] cStringWithEncoding: encoding]) != 0) Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -116,11 +116,11 @@ #import "OFMessagePackExtension.h" #import "OFApplication.h" #import "OFSystemInfo.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFOptionsParser.h" #import "OFTimer.h" #import "OFRunLoop.h" #import "OFSandbox.h" Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -27,11 +27,11 @@ #endif #import "OFException.h" #import "OFString.h" #import "OFArray.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" @@ -177,27 +177,27 @@ if ((string = strerror_r(errNo, buffer, 256)) == NULL) return @"Unknown error (strerror_r failed)"; ret = [OFString stringWithCString: string - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #elif defined(HAVE_STRERROR_R) if (strerror_r(errNo, buffer, 256) != 0) return @"Unknown error (strerror_r failed)"; ret = [OFString stringWithCString: buffer - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; #else # ifdef OF_HAVE_THREADS if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; @try { # endif ret = [OFString stringWithCString: strerror(errNo) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; # ifdef OF_HAVE_THREADS } @finally { if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exception]; } Index: src/of_asprintf.m ================================================================== --- src/of_asprintf.m +++ src/of_asprintf.m @@ -37,11 +37,11 @@ #ifdef OF_HAVE_SYS_TYPES_H # include #endif #import "OFString.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFInitializationFailedException.h" #define MAX_SUBFORMAT_LEN 64 @@ -559,12 +559,11 @@ @try { OFMutableString *tmpStr = [OFMutableString stringWithUTF8String: tmp length: tmpLen]; - OFString *point = - [OFLocalization decimalPoint]; + OFString *point = [OFLocale decimalPoint]; if (point != nil) [tmpStr replaceOccurrencesOfString: point withString: @"."]; if ([tmpStr UTF8StringLength] > INT_MAX) Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -21,11 +21,11 @@ # include /* For memalign() */ #endif #include -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFException.h" /* For some E* -> WSAE* defines */ #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFLockFailedException.h" @@ -346,12 +346,12 @@ ret.length = sizeof(struct sockaddr_in); sin->sin_family = AF_INET; sin->sin_port = OF_BSWAP16_IF_LE(port); - if (inet_pton(AF_INET, [IPv4 cStringWithEncoding: - [OFLocalization encoding]], &sin->sin_addr) != 1) + if (inet_pton(AF_INET, [IPv4 cStringWithEncoding: [OFLocale encoding]], + &sin->sin_addr) != 1) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return ret; @@ -369,12 +369,12 @@ ret.length = sizeof(struct sockaddr_in6); sin6->sin6_family = AF_INET6; sin6->sin6_port = OF_BSWAP16_IF_LE(port); - if (inet_pton(AF_INET6, [IPv6 cStringWithEncoding: - [OFLocalization encoding]], &sin6->sin_addr6) != 1) + if (inet_pton(AF_INET6, [IPv6 cStringWithEncoding: [OFLocale encoding]], + &sin6->sin_addr6) != 1) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return ret; Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -19,11 +19,11 @@ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFListTests.m \ - OFLocalizationTests.m \ + OFLocaleTests.m \ OFMethodSignatureTests.m \ OFNumberTests.m \ OFObjectTests.m \ OFPropertyListTests.m \ OFSetTests.m \ ADDED tests/OFLocaleTests.m Index: tests/OFLocaleTests.m ================================================================== --- tests/OFLocaleTests.m +++ tests/OFLocaleTests.m @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFLocale.h" +#import "OFAutoreleasePool.h" + +#import "TestsAppDelegate.h" + +static OFString *module = @"OFLocale"; + +@implementation TestsAppDelegate (OFLocaleTests) +- (void)localeTests +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + + PRINT(GREEN, @"Language: %@", [OFLocale language]); + + PRINT(GREEN, @"Territory: %@", [OFLocale territory]); + + PRINT(GREEN, @"Encoding: %@", + of_string_name_of_encoding([OFLocale encoding])); + + PRINT(GREEN, @"Decimal point: %@", [OFLocale decimalPoint]); + + [pool drain]; +} +@end DELETED tests/OFLocalizationTests.m Index: tests/OFLocalizationTests.m ================================================================== --- tests/OFLocalizationTests.m +++ tests/OFLocalizationTests.m @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFLocalization.h" -#import "OFAutoreleasePool.h" - -#import "TestsAppDelegate.h" - -static OFString *module = @"OFLocalization"; - -@implementation TestsAppDelegate (OFLocalizationTests) -- (void)localizationTests -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - - PRINT(GREEN, @"Language: %@", [OFLocalization language]); - - PRINT(GREEN, @"Territory: %@", [OFLocalization territory]); - - PRINT(GREEN, @"Encoding: %@", - of_string_name_of_encoding([OFLocalization encoding])); - - PRINT(GREEN, @"Decimal point: %@", [OFLocalization decimalPoint]); - - [pool drain]; -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -145,12 +145,12 @@ @interface TestsAppDelegate (OFListTests) - (void)listTests; @end -@interface TestsAppDelegate (OFLocalizationTests) -- (void)localizationTests; +@interface TestsAppDelegate (OFLocaleTests) +- (void)localeTests; @end @interface TestsAppDelegate (OFMD5HashTests) - (void)MD5HashTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -432,11 +432,11 @@ #if defined(OF_HAVE_PLUGINS) [self pluginTests]; #endif [self systemInfoTests]; - [self localizationTests]; + [self localeTests]; #if defined(OF_IOS) [self outputString: [OFString stringWithFormat: @"%d tests failed!", _fails] inColor: NO_COLOR]; Index: utils/ofarc/GZIPArchive.m ================================================================== --- utils/ofarc/GZIPArchive.m +++ utils/ofarc/GZIPArchive.m @@ -18,11 +18,11 @@ #include "config.h" #import "OFApplication.h" #import "OFFileManager.h" #import "OFStdIOStream.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "GZIPArchive.h" #import "OFArc.h" static OFArc *app; Index: utils/ofarc/LHAArchive.m ================================================================== --- utils/ofarc/LHAArchive.m +++ utils/ofarc/LHAArchive.m @@ -18,11 +18,11 @@ #include "config.h" #import "OFApplication.h" #import "OFDate.h" #import "OFFileManager.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" Index: utils/ofarc/OFArc.m ================================================================== --- utils/ofarc/OFArc.m +++ utils/ofarc/OFArc.m @@ -21,11 +21,11 @@ #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFFileManager.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFURL.h" @@ -189,13 +189,13 @@ [sandbox release]; } #endif #ifndef OF_AMIGAOS - [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; + [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else - [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"]; + [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { @@ -357,11 +357,11 @@ @try { [archive extractFiles: files]; } @catch (OFCreateDirectoryFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_create_directory", @"Failed to create directory %[dir]: %[error]", @"dir", [[e URL] fileSystemRepresentation], @@ -368,11 +368,11 @@ @"error", error)]; _exitStatus = 1; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", [e path], @@ -425,11 +425,11 @@ file = [OFFile fileWithPath: path mode: fileModeString]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", [e path], @@ -493,20 +493,20 @@ @throw e; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", path, @"error", error)]; goto error; } @catch (OFSeekFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file", @"Failed to seek in file %[file]: %[error]", @"file", path, @"error", error)]; goto error; @@ -603,11 +603,11 @@ length = [input readIntoBuffer: buffer length: BUFFER_SIZE]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stdout writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", fileName, @"error", error)]; @@ -618,11 +618,11 @@ [output writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization encoding]]; + encoding: [OFLocale encoding]]; [of_stdout writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_write_file", @"Failed to write file %[file]: %[error]", @"file", fileName, @"error", error)]; Index: utils/ofarc/TarArchive.m ================================================================== --- utils/ofarc/TarArchive.m +++ utils/ofarc/TarArchive.m @@ -18,11 +18,11 @@ #include "config.h" #import "OFApplication.h" #import "OFDate.h" #import "OFFileManager.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" Index: utils/ofarc/ZIPArchive.m ================================================================== --- utils/ofarc/ZIPArchive.m +++ utils/ofarc/ZIPArchive.m @@ -20,11 +20,11 @@ #include #import "OFApplication.h" #import "OFDate.h" #import "OFFileManager.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -26,11 +26,11 @@ #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" #import "OFStdIOStream.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFSandbox.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" @@ -91,13 +91,13 @@ [sandbox release]; } #endif #ifndef OF_AMIGAOS - [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; + [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else - [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"]; + [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"]; #endif if ([arguments count] < 2) help(); @@ -124,12 +124,11 @@ file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization - encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", [e path], @@ -150,12 +149,11 @@ length = [file readIntoBuffer: buffer length: 1024]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror([e errNo]) - encoding: [OFLocalization - encoding]]; + encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_read_file", @"Failed to read %[file]: %[error]", @"file", path, Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -30,11 +30,11 @@ #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFTLSSocket.h" #import "OFURL.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "OFSandbox.h" #import "OFAddressTranslationFailedException.h" #import "OFConnectionFailedException.h" #import "OFHTTPRequestFailedException.h" @@ -395,13 +395,13 @@ [sandbox release]; } #endif #ifndef OF_AMIGAOS - [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; + [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else - [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"]; + [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { Index: utils/ofhttp/ProgressBar.m ================================================================== --- utils/ofhttp/ProgressBar.m +++ utils/ofhttp/ProgressBar.m @@ -20,11 +20,11 @@ #include #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" -#import "OFLocalization.h" +#import "OFLocale.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024)