@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2022 Jonathan Schleifer + * Copyright (c) 2008-2024 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 @@ -16,24 +16,27 @@ #include "config.h" #include #import "OFLocale.h" -#import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" +#import "OFIRI.h" #import "OFNumber.h" +#import "OFString.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" #ifdef OF_AMIGAOS +# define Class IntuitionClass # include # include # include +# undef Class #endif static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; @@ -359,16 +362,14 @@ + (OFString *)decimalSeparator { return currentLocale.decimalSeparator; } -#ifdef OF_HAVE_FILES -+ (void)addLocalizationDirectory: (OFString *)path ++ (void)addLocalizationDirectoryIRI: (OFIRI *)IRI { - [currentLocale addLocalizationDirectory: path]; + [currentLocale addLocalizationDirectoryIRI: IRI]; } -#endif - (instancetype)init { self = [super init]; @@ -378,11 +379,15 @@ if (currentLocale != nil) @throw [OFInitializationFailedException exceptionWithClass: self.class]; +# ifdef OF_MSDOS + _encoding = OFStringEncodingCodepage437; +# else _encoding = OFStringEncodingUTF8; +# endif _decimalSeparator = @"."; _localizedStrings = [[OFMutableArray alloc] init]; if ((locale = setlocale(LC_ALL, "")) != NULL) _decimalSeparator = [[OFString alloc] @@ -492,25 +497,25 @@ [_localizedStrings release]; [super dealloc]; } -#ifdef OF_HAVE_FILES -- (void)addLocalizationDirectory: (OFString *)path +- (void)addLocalizationDirectoryIRI: (OFIRI *)IRI { void *pool; - OFString *mapPath, *languageCode, *countryCode, *localizationFile; + OFIRI *mapIRI, *localizationIRI; + OFString *languageCode, *countryCode, *localizationFile; OFDictionary *map; if (_languageCode == nil) return; pool = objc_autoreleasePoolPush(); - mapPath = [path stringByAppendingPathComponent: @"localizations.json"]; + mapIRI = [IRI IRIByAppendingPathComponent: @"localizations.json"]; @try { - map = [[OFString stringWithContentsOfFile: mapPath] + map = [[OFString stringWithContentsOfIRI: mapIRI] objectByParsingJSON]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } @@ -530,19 +535,18 @@ if (localizationFile == nil) { objc_autoreleasePoolPop(pool); return; } - localizationFile = [path stringByAppendingPathComponent: + localizationIRI = [IRI IRIByAppendingPathComponent: [localizationFile stringByAppendingString: @".json"]]; - [_localizedStrings addObject: [[OFString stringWithContentsOfFile: - localizationFile] objectByParsingJSON]]; + [_localizedStrings addObject: [[OFString stringWithContentsOfIRI: + localizationIRI] objectByParsingJSON]]; objc_autoreleasePoolPop(pool); } -#endif - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback, ... { OFString *ret;