ObjFW  Check-in [0e82e3b843]

Overview
Comment:OFLocalization: Don't lower language and territory

Instead, lowercase it before looking it up.

This allows getting the original values provided by setlocale().

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0e82e3b843e7f6ba14bdd49ffb04e9880b35b8fd1700403673c6f9d09f5c8bfc
User & Date: js on 2017-02-27 22:04:21
Other Links: manifest | tags
Context
2017-03-12
00:31
configure: Check if assert is buggy with -pedantic check-in: 7d9ac574a8 user: js tags: trunk
2017-02-27
22:04
OFLocalization: Don't lower language and territory check-in: 0e82e3b843 user: js tags: trunk
21:57
ofhttp: Move formatting out of localized strings check-in: 7ffbd24169 user: js tags: trunk
Changes

Modified src/OFLocalization.m from [0a1b003490] to [b0fb42c722].

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
		return self;
	}

	locale = of_strdup(locale);

	@try {
		char *tmp;
		size_t tmpLen;

		/* We don't care for extras behind the @ */
		if ((tmp = strrchr(locale, '@')) != NULL)
			*tmp = '\0';

		/* Encoding */
		if ((tmp = strrchr(locale, '.')) != NULL) {







<







79
80
81
82
83
84
85

86
87
88
89
90
91
92
		return self;
	}

	locale = of_strdup(locale);

	@try {
		char *tmp;


		/* We don't care for extras behind the @ */
		if ((tmp = strrchr(locale, '@')) != NULL)
			*tmp = '\0';

		/* Encoding */
		if ((tmp = strrchr(locale, '.')) != NULL) {
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
			}
		}

		/* Territory */
		if ((tmp = strrchr(locale, '_')) != NULL) {
			*tmp++ = '\0';

			tmpLen = strlen(tmp);
			for (size_t i = 0; i < tmpLen; i++)
				tmp[i] = of_ascii_tolower(tmp[i]);

			_territory = [[OFString alloc]
			    initWithCString: tmp
				   encoding: OF_STRING_ENCODING_ASCII
				     length: tmpLen];
		}

		tmpLen = strlen(locale);
		for (size_t i = 0; i < tmpLen; i++)
			locale[i] = of_ascii_tolower(locale[i]);

		_language = [[OFString alloc]
		    initWithCString: locale
			   encoding: OF_STRING_ENCODING_ASCII
			     length: tmpLen];

		_decimalPoint = [[OFString alloc]
		    initWithCString: localeconv()->decimal_point
			   encoding: _encoding];
	} @catch (id e) {
		[self release];
		@throw e;







<
<
<
<


|
<


<
<
<
<


|
<







103
104
105
106
107
108
109




110
111
112

113
114




115
116
117

118
119
120
121
122
123
124
			}
		}

		/* Territory */
		if ((tmp = strrchr(locale, '_')) != NULL) {
			*tmp++ = '\0';





			_territory = [[OFString alloc]
			    initWithCString: tmp
				   encoding: OF_STRING_ENCODING_ASCII];

		}





		_language = [[OFString alloc]
		    initWithCString: locale
			   encoding: OF_STRING_ENCODING_ASCII];


		_decimalPoint = [[OFString alloc]
		    initWithCString: localeconv()->decimal_point
			   encoding: _encoding];
	} @catch (id e) {
		[self release];
		@throw e;
155
156
157
158
159
160
161
162
163



164
165
166
167
168
169
170
171
172
173
- (void)addLanguageDirectory: (OFString*)path
{
	void *pool = objc_autoreleasePoolPush();
	OFString *mapPath =
	    [path stringByAppendingPathComponent: @"languages.json"];
	OFDictionary *map =
	    [[OFString stringWithContentsOfFile: mapPath] JSONValue];
	OFString *languageFile;




	languageFile = [[map objectForKey: _language] objectForKey: _territory];
	if (languageFile == nil)
		languageFile = [[map objectForKey: _language]
		    objectForKey: @""];

	if (languageFile == nil) {
		objc_autoreleasePoolPop(pool);
		return;
	}








|

>
>
>
|

|







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
- (void)addLanguageDirectory: (OFString*)path
{
	void *pool = objc_autoreleasePoolPush();
	OFString *mapPath =
	    [path stringByAppendingPathComponent: @"languages.json"];
	OFDictionary *map =
	    [[OFString stringWithContentsOfFile: mapPath] JSONValue];
	OFString *language, *territory, *languageFile;

	language = [_language lowercaseString];
	territory = [_territory lowercaseString];

	languageFile = [[map objectForKey: language] objectForKey: territory];
	if (languageFile == nil)
		languageFile = [[map objectForKey: language]
		    objectForKey: @""];

	if (languageFile == nil) {
		objc_autoreleasePoolPop(pool);
		return;
	}