ObjFW
OFLocale.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFString.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
32 #define OF_LOCALIZED(ID, ...) \
33  [[OFLocale currentLocale] localizedStringForID: ID \
34  fallback: __VA_ARGS__, nil]
35 
36 @class OFMutableArray OF_GENERIC(ObjectType);
37 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
38 
44 OF_SUBCLASSING_RESTRICTED
45 @interface OFLocale: OFObject
46 {
47  OFString *_Nullable _language, *_Nullable _territory;
48  of_string_encoding_t _encoding;
49  OFString *_decimalPoint;
50  OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *)
51  *_localizedStrings;
52 }
53 
54 #ifdef OF_HAVE_CLASS_PROPERTIES
55 @property (class, readonly, nullable, nonatomic) OFLocale *currentLocale;
56 @property (class, readonly, nullable, nonatomic) OFString *language;
57 @property (class, readonly, nullable, nonatomic) OFString *territory;
58 @property (class, readonly, nonatomic) of_string_encoding_t encoding;
59 @property (class, readonly, nullable, nonatomic) OFString *decimalPoint;
60 #endif
61 
67 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *language;
68 
74 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *territory;
75 
84 @property (readonly, nonatomic) of_string_encoding_t encoding;
85 
89 @property (readonly, nonatomic) OFString *decimalPoint;
90 
100 + (nullable OFLocale *)currentLocale;
101 
109 + (nullable OFString *)language;
110 
118 + (nullable OFString *)territory;
119 
130 + (of_string_encoding_t)encoding;
131 
137 + (nullable OFString *)decimalPoint;
138 
139 #ifdef OF_HAVE_FILES
145 + (void)addLanguageDirectory: (OFString *)path;
146 #endif
147 
158 - (instancetype)init;
159 
160 #ifdef OF_HAVE_FILES
166 - (void)addLanguageDirectory: (OFString *)path;
167 #endif
168 
188 - (OFString *)localizedStringForID: (OFConstantString *)ID
189  fallback: (id)fallback, ... OF_SENTINEL;
190 
213 - (OFString *)localizedStringForID: (OFConstantString *)ID
214  fallback: (id)fallback
215  arguments: (va_list)arguments;
216 @end
217 
218 OF_ASSUME_NONNULL_END
of_string_encoding_t
The encoding of a string.
Definition: OFString.h:68
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:58
A class for querying the locale and retrieving localized strings.
Definition: OFLocale.h:46
OFString * territory
The territory of the locale for messages.
Definition: OFLocale.h:74
OFString * language
The language of the locale for messages.
Definition: OFLocale.h:67
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:44
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class for handling strings.
Definition: OFString.h:132