1 /* |
1 /* |
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
89 char *hyphenPos = strchr(languageString, '-'); |
89 char *hyphenPos = strchr(languageString, '-'); |
90 int langStrLen = strlen(languageString); |
90 int langStrLen = strlen(languageString); |
91 |
91 |
92 if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en" |
92 if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en" |
93 languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn" |
93 languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn" |
94 CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()), |
94 CFLocaleRef cflocale = CFLocaleCopyCurrent(); |
95 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding()); |
95 if (cflocale != NULL) { |
96 char *underscorePos = strrchr(localeString, '_'); |
96 CFStringGetCString(CFLocaleGetIdentifier(cflocale), |
97 char *region = NULL; |
97 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding()); |
98 |
98 char *underscorePos = strrchr(localeString, '_'); |
99 if (underscorePos != NULL) { |
99 char *region = NULL; |
100 region = underscorePos + 1; |
100 |
101 } |
101 if (underscorePos != NULL) { |
102 |
102 region = underscorePos + 1; |
103 if (region != NULL) { |
103 } |
104 strcat(languageString, "-"); |
104 |
105 strcat(languageString, region); |
105 if (region != NULL) { |
|
106 strcat(languageString, "-"); |
|
107 strcat(languageString, region); |
|
108 } |
|
109 CFRelease(cflocale); |
106 } |
110 } |
107 } |
111 } |
108 |
112 |
109 retVal = languageString; |
113 retVal = languageString; |
110 } |
114 } |
111 break; |
115 break; |
112 |
116 |
113 default: |
117 default: |
114 { |
118 { |
115 if (!CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()), |
119 CFLocaleRef cflocale = CFLocaleCopyCurrent(); |
116 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) { |
120 if (cflocale != NULL) { |
|
121 if (!CFStringGetCString(CFLocaleGetIdentifier(cflocale), |
|
122 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) { |
|
123 CFRelease(cflocale); |
|
124 return NULL; |
|
125 } |
|
126 |
|
127 retVal = localeString; |
|
128 CFRelease(cflocale); |
|
129 } else { |
117 return NULL; |
130 return NULL; |
118 } |
131 } |
119 |
|
120 retVal = localeString; |
|
121 } |
132 } |
122 break; |
133 break; |
123 } |
134 } |
124 |
135 |
125 if (retVal != NULL) { |
136 if (retVal != NULL) { |