summaryrefslogtreecommitdiff
path: root/libc/debian/patches/illumos-2252-gettext.patch
blob: 6ca3f9c1676ecdb117606f15f7a6f786518144fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Description: gettext should search in several directories
 Search for message catalogs not only in locale dir (e. g. "ru_RU.UTF-8"),
 but also in "ru_RU" and "ru".
Bug: https://www.illumos.org/issues/2252
Index: b/usr/src/lib/libc/port/i18n/gettext_util.c
===================================================================
--- a/usr/src/lib/libc/port/i18n/gettext_util.c
+++ b/usr/src/lib/libc/port/i18n/gettext_util.c
@@ -87,6 +87,8 @@ mk_msgfile(struct msg_pack *mp)
 	const char *q;
 	char	*p;
 	const char	*catstr;
+	char *country;
+	char *charset;
 	uint32_t	cblen, loclen, catlen, totallen;
 
 #ifdef GETTEXT_DEBUG
@@ -126,9 +128,39 @@ mk_msgfile(struct msg_pack *mp)
 		return (NULL);
 
 	q = mp->locale;
-	while (*p++ = *q++)
-		;
-	*(p - 1) = '/';
+	country = NULL;
+	charset = NULL;
+	while (*p = *q++) {
+		switch (*p) { /* ru_RU.UTF-8 */
+			case '_': country = p; break;
+			case '.': charset = p; break;
+			default:;
+		}
+		p++;
+	}
+
+	/* if /usr/share/locale/<lang_country.charset> does not exist: */
+	if (access(mp->msgfile, F_OK)) {
+		/* cut off charset if any */
+		if (NULL != charset) {
+			*charset = '\0';
+			p = charset;
+			/* if /usr/share/locale/<lang_country> does not exist: */
+			if (access(mp->msgfile, F_OK)) {
+				/* cut off country if any */
+				if (NULL != country) {
+					*country = '\0';
+					p = country;
+					/* if /usr/share/locale/<lang> does not exist: */
+					if (access(mp->msgfile, F_OK)) {
+						return (NULL);
+					}
+				}
+			}
+		}
+	}
+
+	*p++ = '/';
 	while (*p++ = *catstr++)
 		;
 	*(p - 1) = '/';