MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / getBundle

Method getBundle

src/common/BundleMgr.cpp:42–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42Bundle* 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

Callers 4

callbackMethod · 0.80
localBZDBCallbackMethod · 0.80
postWindowInitFunction · 0.80
mainFunction · 0.80

Calls 6

findMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45
resizeMethod · 0.45
loadMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected