// function to retrieve localized version of a file // parameters: // file path to file that needs a localized version // absolute if true provide absolute path, if false relative path // root path to root of widget // return: // QString path of localized file // QString WebAppLocalizer::getLocalizedFile(const QString& file, const bool absolute, const QString& root) { QString userAgentLang = platformLanguage(); if (userAgentLang.isEmpty() ) return file; QChar sep = QDir::separator(); QString widgetRoot = QDir::fromNativeSeparators(root) + sep; // Find out relative path for with file name, without locales and language QString relativeFile = file; if (absolute) { relativeFile = QDir::fromNativeSeparators(file.mid(widgetRoot.length())); if (relativeFile.startsWith("locales/")) relativeFile = relativeFile.mid(relativeFile.indexOf('/', 8)+1); else relativeFile = file.mid(root.length()+1); } // Cache locales directory if not already done QString cacheDir = widgetRoot+"locales/"; if (!s_widgetExistsCache.contains(cacheDir)) { QStringList dirList = QDir(cacheDir).entryList(QDir::CaseSensitive| QDir::Dirs| QDir::NoDotAndDotDot); foreach(const QString &dir, dirList) { // Have to cache real path because of case sensitivity s_widgetExistsCache.insert(cacheDir.toLower()+dir.toLower()+sep, cacheDir+dir+sep); }
Vector<String> platformUserPreferredLanguages() { Vector<String> userPreferredLanguages; userPreferredLanguages.append(platformLanguage()); return userPreferredLanguages; }