void TranslationManager::setLanguage(const String &lang) { // Get lang index. int langIndex = -1; String langStr(lang); if (langStr.empty()) langStr = g_system->getSystemLanguage(); // Search for the given language or a variant of it. langIndex = findMatchingLanguage(langStr); // Try to find a partial match taking away parts of the original language. const char *lastSep; String langCut(langStr); while ((langIndex == -1) && (lastSep = strrchr(langCut.c_str(), '_'))) { langCut = String(langCut.c_str(), lastSep); langIndex = findMatchingLanguage(langCut); } // Load messages for that language. // Call it even if the index is -1 to unload previously loaded translations. if (langIndex != _currentLang) { loadLanguageDat(langIndex); _currentLang = langIndex; } }
JSObject *JSOS::RegisterModule(JSContext *cx) { JS::RootedObject exports(cx, JSOS::ExposeObject(cx, "OS")); // Platform JS::RootedString platformStr(cx, JSUtils::NewStringWithEncoding(cx, NIDIUM_PLATFORM, strlen(NIDIUM_PLATFORM), "utf8")); JS::RootedValue platform(cx, JS::StringValue(platformStr)); JS_DefineProperty(cx, exports, "platform", platform, JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE); // Language #ifdef NIDIUM_PRODUCT_FRONTEND Interface::SystemInterface* interface = Interface::SystemInterface::GetInstance(); const char *clang = interface->getLanguage(); JS::RootedString langStr(cx, JSUtils::NewStringWithEncoding(cx, clang, strlen(clang), "utf8")); JS::RootedValue lang(cx, JS::StringValue(langStr)); JS_DefineProperty(cx, exports, "language", lang, JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE); #endif return exports; }
static LanguageSpecificCasingBehavior GetCasingFor(const nsIAtom* aLang) { if (!aLang) { return eLSCB_None; } if (aLang == nsGkAtoms::tr || aLang == nsGkAtoms::az || aLang == nsGkAtoms::ba || aLang == nsGkAtoms::crh || aLang == nsGkAtoms::tt) { return eLSCB_Turkish; } if (aLang == nsGkAtoms::nl) { return eLSCB_Dutch; } if (aLang == nsGkAtoms::el) { return eLSCB_Greek; } if (aLang == nsGkAtoms::ga) { return eLSCB_Irish; } // Is there a region subtag we should ignore? nsAtomString langStr(const_cast<nsIAtom*>(aLang)); int index = langStr.FindChar('-'); if (index > 0) { langStr.Truncate(index); nsCOMPtr<nsIAtom> truncatedLang = do_GetAtom(langStr); return GetCasingFor(truncatedLang); } return eLSCB_None; }
// /// Gets the language name string associated with a language/charset code // tstring TModuleVersionInfo::GetLanguageName(uint lang) { TTmpBuffer<tchar> langStr(128); TVersion::VerLanguageName(uint(lang), langStr, 128); return tstring((tchar*)langStr); }
std::string CLevelParser::InjectLevelPaths(const std::string& path, const std::string& defaultDir) { std::string newPath = path; if(!m_pathLvl.empty() ) boost::replace_all(newPath, "%lvl%", m_pathLvl); if(!m_pathChap.empty()) boost::replace_all(newPath, "%chap%", m_pathChap); if(!m_pathCat.empty() ) boost::replace_all(newPath, "%cat%", m_pathCat); if(newPath == path && !path.empty()) { newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath; } std::string langPath = newPath; std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar()); boost::replace_all(langPath, "%lng%", langStr); if(CResourceManager::Exists(langPath)) return langPath; // Fallback to English if file doesn't exist boost::replace_all(newPath, "%lng%", "E"); if(CResourceManager::Exists(newPath)) return newPath; return langPath; // Return current language file if none of the files exist }