| 40 | } |
| 41 | |
| 42 | Bundle* BundleMgr::getBundle(const std::string& locale, bool setcur /*= true*/) { |
| 43 | BundleMap::iterator it = bundles.find(locale); |
| 44 | if (it != bundles.end()) { |
| 45 | if (setcur) { currentBundle = it->second; } |
| 46 | return it->second; |
| 47 | } |
| 48 | |
| 49 | Bundle* parentBundle = NULL; |
| 50 | if (locale.length() > 0) { |
| 51 | std::string parentLocale = locale; |
| 52 | |
| 53 | int underPos = parentLocale.find_last_of('_'); |
| 54 | if (underPos >= 0) { |
| 55 | parentLocale = parentLocale.substr(0, underPos); |
| 56 | } |
| 57 | else { |
| 58 | parentLocale.resize(0); |
| 59 | } |
| 60 | parentBundle = getBundle(parentLocale); |
| 61 | } |
| 62 | |
| 63 | Bundle* pB = new Bundle(parentBundle); |
| 64 | |
| 65 | std::string path = bundlePath + "/l10n/" + bundleName; |
| 66 | |
| 67 | if (locale.length() > 0) { |
| 68 | path += "_" + locale; |
| 69 | } |
| 70 | path += ".po"; |
| 71 | |
| 72 | /* FIXME -- this needs to be in libplatform not here -- causes libcommon |
| 73 | * to require corefoundation framework |
| 74 | */ |
| 75 | #if defined(__APPLE__) |
| 76 | // This is MacOS X. Use the CoreFoundation resource location API |
| 77 | // to find the correct language resource if 'default' is specified. |
| 78 | if (locale.length() == 7 && locale.compare("default") == 0) { |
| 79 | char localePath[512]; |
| 80 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
| 81 | CFArrayRef locales = NULL; |
| 82 | CFURLRef localeURL = NULL; |
| 83 | // Look for a resource in the main bundle by name and type. |
| 84 | do { |
| 85 | if (mainBundle == NULL) { break; } |
| 86 | locales = CFBundleCopyResourceURLsOfType(mainBundle, CFSTR("po"), NULL); |
| 87 | if (locales == NULL || CFArrayGetCount(locales) == 0) { break; } |
| 88 | localeURL = (CFURLRef) CFArrayGetValueAtIndex(locales, 0); |
| 89 | if (localeURL != NULL && ::CFURLGetFileSystemRepresentation( |
| 90 | localeURL, true, reinterpret_cast<UInt8*>(localePath), sizeof(localePath)) |
| 91 | ) { |
| 92 | path = localePath; |
| 93 | } |
| 94 | } |
| 95 | while (0); |
| 96 | CFRelease(locales); |
| 97 | } |
| 98 | #endif |
| 99 |
no test coverage detected