From 28bb7a67f7ce3cfe2cd76aecdde51c36515e5066 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 22 Jun 2012 14:34:51 +0200 Subject: [PATCH] startup language available on the all OS --- src/frameworks/UBFileSystemUtils.cpp | 4 +- src/frameworks/UBFileSystemUtils.h | 2 +- src/frameworks/UBPlatformUtils_mac.mm | 69 ++++++++++++++++++++------- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 5d9e018c..658a4389 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -177,7 +177,7 @@ void UBFileSystemUtils::cleanupGhostTempFolders(const QString& templateString) } -QStringList UBFileSystemUtils::allFiles(const QString& pDirPath) +QStringList UBFileSystemUtils::allFiles(const QString& pDirPath, bool isRecursive) { QStringList result; if (pDirPath == "" || pDirPath == "." || pDirPath == "..") @@ -187,7 +187,7 @@ QStringList UBFileSystemUtils::allFiles(const QString& pDirPath) foreach(QFileInfo dirContent, dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot , QDir::Name)) { - if (dirContent.isDir()) + if (isRecursive && dirContent.isDir()) { result << allFiles(dirContent.absoluteFilePath()); } diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h index bd20755b..26ec89d2 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -37,7 +37,7 @@ class UBFileSystemUtils static QFileInfoList allElementsInDirectory(const QString& pDirPath); - static QStringList allFiles(const QString& pDirPath); + static QStringList allFiles(const QString& pDirPath, const bool isRecurive=true); static bool deleteDir(const QString& pDirPath); diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index e94d254b..33d2bc25 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -184,31 +184,64 @@ void UBPlatformUtils::fadeDisplayIn() } } -QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) -{ - QString qmPath; - NSString* filePrefix = [[NSString alloc] initWithUTF8String:(const char*)(pFilePrefix.toUtf8())]; +//QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) +//{ +// QString qmPath; +// NSString* filePrefix = [[NSString alloc] initWithUTF8String:(const char*)(pFilePrefix.toUtf8())]; + +// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + +// NSString *lprojPath = [[[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"] stringByDeletingLastPathComponent]; +// if (lprojPath) +// { +// NSString *lang = [[lprojPath lastPathComponent] stringByDeletingPathExtension]; +// NSString *translationFilePath = [lprojPath stringByAppendingPathComponent:[[filePrefix stringByAppendingString:lang] stringByAppendingPathExtension:@"qm"]]; +// qmPath = QString::fromUtf8([translationFilePath UTF8String], strlen([translationFilePath UTF8String])); +// } + +// [pool drain]; +// return qmPath; +//} + +//QString UBPlatformUtils::preferredLanguage() +//{ +// QFileInfo qmFileInfo = QFileInfo(preferredTranslation("sankore_")); +// QDir lprojPath = qmFileInfo.dir(); +// QFileInfo lprojFileInfo = QFileInfo(lprojPath.absolutePath()); +// return lprojFileInfo.baseName(); +//} + +QStringList UBPlatformUtils::availableTranslations() +{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *lprojPath = [[NSBundle mainBundle] resourcePath]; + QString translationsPath = QString::fromUtf8([lprojPath UTF8String], strlen([lprojPath UTF8String])); + QStringList translationsList = UBFileSystemUtils::allFiles(translationsPath, false); + QRegExp sankoreTranslationFiles(".*lproj"); + translationsList=translationsList.filter(sankoreTranslationFiles); + [pool drain]; + return translationsList.replaceInStrings(QRegExp("(.*)/(.*).lproj"),"\\2"); +} - NSString *lprojPath = [[[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"] stringByDeletingLastPathComponent]; - if (lprojPath) - { - NSString *lang = [[lprojPath lastPathComponent] stringByDeletingPathExtension]; - NSString *translationFilePath = [lprojPath stringByAppendingPathComponent:[[filePrefix stringByAppendingString:lang] stringByAppendingPathExtension:@"qm"]]; - qmPath = QString::fromUtf8([translationFilePath UTF8String], strlen([translationFilePath UTF8String])); - } - +QString UBPlatformUtils::translationPath(QString pFilePrefix, QString pLanguage) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *lprojPath = [[NSBundle mainBundle] resourcePath]; + QString translationsPath = QString::fromUtf8([lprojPath UTF8String], strlen([lprojPath UTF8String])); [pool drain]; - return qmPath; + return translationsPath + "/" + pLanguage + ".lproj/" + pFilePrefix + pLanguage + ".qm"; } -QString UBPlatformUtils::preferredLanguage() +QString UBPlatformUtils::systemLanguage() { - QFileInfo qmFileInfo = QFileInfo(preferredTranslation("sankore_")); - QDir lprojPath = qmFileInfo.dir(); - QFileInfo lprojFileInfo = QFileInfo(lprojPath.absolutePath()); - return lprojFileInfo.baseName(); + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; + NSArray* languages = [defs objectForKey:@"AppleLanguages"]; + NSString* preferredLang = [languages objectAtIndex:0]; + QString result = QString::fromUtf8([preferredLang UTF8String], strlen([preferredLang UTF8String])); + [pool drain]; + return result; } void UBPlatformUtils::runInstaller(const QString &installerFilePath)