| 1227 | */ |
| 1228 | |
| 1229 | static const char * /* O - Locale string */ |
| 1230 | appleLangDefault(void) |
| 1231 | { |
| 1232 | CFBundleRef bundle; /* Main bundle (if any) */ |
| 1233 | CFArrayRef bundleList; /* List of localizations in bundle */ |
| 1234 | CFPropertyListRef localizationList = NULL; |
| 1235 | /* List of localization data */ |
| 1236 | CFStringRef languageName; /* Current name */ |
| 1237 | char *lang; /* LANG environment variable */ |
| 1238 | _cups_globals_t *cg = _cupsGlobals(); |
| 1239 | /* Pointer to library globals */ |
| 1240 | |
| 1241 | |
| 1242 | DEBUG_puts("2appleLangDefault()"); |
| 1243 | |
| 1244 | /* |
| 1245 | * Only do the lookup and translation the first time. |
| 1246 | */ |
| 1247 | |
| 1248 | if (!cg->language[0]) |
| 1249 | { |
| 1250 | if (getenv("SOFTWARE") != NULL && (lang = getenv("LANG")) != NULL) |
| 1251 | { |
| 1252 | DEBUG_printf(("3appleLangDefault: Using LANG=%s", lang)); |
| 1253 | strlcpy(cg->language, lang, sizeof(cg->language)); |
| 1254 | return (cg->language); |
| 1255 | } |
| 1256 | else if ((bundle = CFBundleGetMainBundle()) != NULL && |
| 1257 | (bundleList = CFBundleCopyBundleLocalizations(bundle)) != NULL) |
| 1258 | { |
| 1259 | CFURLRef resources = CFBundleCopyResourcesDirectoryURL(bundle); |
| 1260 | |
| 1261 | DEBUG_puts("3appleLangDefault: Getting localizationList from bundle."); |
| 1262 | |
| 1263 | if (resources) |
| 1264 | { |
| 1265 | CFStringRef cfpath = CFURLCopyPath(resources); |
| 1266 | char path[1024]; |
| 1267 | |
| 1268 | if (cfpath) |
| 1269 | { |
| 1270 | /* |
| 1271 | * See if we have an Info.plist file in the bundle... |
| 1272 | */ |
| 1273 | |
| 1274 | CFStringGetCString(cfpath, path, sizeof(path), kCFStringEncodingUTF8); |
| 1275 | DEBUG_printf(("3appleLangDefault: Got a resource URL (\"%s\")", path)); |
| 1276 | strlcat(path, "Contents/Info.plist", sizeof(path)); |
| 1277 | |
| 1278 | if (!access(path, R_OK)) |
| 1279 | localizationList = CFBundleCopyPreferredLocalizationsFromArray(bundleList); |
| 1280 | else |
| 1281 | DEBUG_puts("3appleLangDefault: No Info.plist, ignoring resource URL..."); |
| 1282 | |
| 1283 | CFRelease(cfpath); |
| 1284 | } |
| 1285 | |
| 1286 | CFRelease(resources); |
no test coverage detected