ObjFW
Loading...
Searching...
No Matches
OFLocale.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21#import "OFString.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
25@class OFIRI;
26
40#define OF_LOCALIZED(ID, ...) \
41 [[OFLocale currentLocale] localizedStringForID: ID \
42 fallback: __VA_ARGS__, nil]
43
44@class OFMutableArray OF_GENERIC(ObjectType);
45@class OFDictionary OF_GENERIC(KeyType, ObjectType);
46
52OF_SUBCLASSING_RESTRICTED
53@interface OFLocale: OFObject
54{
55 OFString *_Nullable _languageCode, *_Nullable _countryCode;
56 OFStringEncoding _encoding;
57 OFString *_decimalSeparator;
58 OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *)
59 *_localizedStrings;
60}
61
62#ifdef OF_HAVE_CLASS_PROPERTIES
63@property (class, readonly, nullable, nonatomic) OFLocale *currentLocale;
64@property (class, readonly, nullable, nonatomic) OFString *languageCode;
65@property (class, readonly, nullable, nonatomic) OFString *countryCode;
66@property (class, readonly, nonatomic) OFStringEncoding encoding;
67@property (class, readonly, nullable, nonatomic) OFString *decimalSeparator;
68#endif
69
75@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *languageCode;
76
82@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *countryCode;
83
92@property (readonly, nonatomic) OFStringEncoding encoding;
93
97@property (readonly, nonatomic) OFString *decimalSeparator;
98
107+ (nullable OFLocale *)currentLocale;
108
116+ (nullable OFString *)languageCode;
117
125+ (nullable OFString *)countryCode;
126
137+ (OFStringEncoding)encoding;
138
144+ (nullable OFString *)decimalSeparator;
145
151+ (void)addLocalizationDirectoryIRI: (OFIRI *)IRI;
152
153- (instancetype)init
154 OF_DEPRECATED(ObjFW, 1, 1,
155 "Manually creating an OFLocale is no longer necessary. "
156 "Use +[OFLocale currentLocale] instead.");
157
163- (void)addLocalizationDirectoryIRI: (OFIRI *)IRI;
164
184- (OFString *)localizedStringForID: (OFConstantString *)ID
185 fallback: (id)fallback, ... OF_SENTINEL;
186
211- (OFString *)localizedStringForID: (OFConstantString *)ID
212 fallback: (id)fallback
213 arguments: (va_list)arguments;
214@end
215
216OF_ASSUME_NONNULL_END
OFStringEncoding
The encoding of a string.
Definition OFString.h:65
A class for storing constant strings using the @"" literal.
Definition OFConstantString.h:42
An abstract class for storing objects in a dictionary.
Definition OFDictionary.h:84
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition OFIRI.h:41
A class for querying the locale and retrieving localized strings.
Definition OFLocale.h:54
OFString * languageCode
The language code of the locale for messages.
Definition OFLocale.h:75
OFString * countryCode
The country code of the locale for messages.
Definition OFLocale.h:82
An abstract class for storing, adding and removing objects in an array.
Definition OFMutableArray.h:48
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A class for handling strings.
Definition OFString.h:143