summaryrefslogtreecommitdiff
path: root/lib/localization.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:23:19 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:23:19 +0200
commit0887aee8c54d0ed51bb2031431e2bcdafebb4c6e (patch)
tree69537ceb9787bb25ac363cc4e6cdaf0804d78363 /lib/localization.cpp
parent5.12 (diff)
downloadFreeFileSync-0887aee8c54d0ed51bb2031431e2bcdafebb4c6e.tar.gz
FreeFileSync-0887aee8c54d0ed51bb2031431e2bcdafebb4c6e.tar.bz2
FreeFileSync-0887aee8c54d0ed51bb2031431e2bcdafebb4c6e.zip
5.13
Diffstat (limited to 'lib/localization.cpp')
-rw-r--r--lib/localization.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/localization.cpp b/lib/localization.cpp
index 78e03545..33494cf4 100644
--- a/lib/localization.cpp
+++ b/lib/localization.cpp
@@ -20,6 +20,10 @@
#include "parse_lng.h"
#include "ffs_paths.h"
+#ifdef FFS_MAC
+#include <CoreServices/CoreServices.h>
+#endif
+
using namespace zen;
@@ -129,8 +133,8 @@ struct LessTranslation : public std::binary_function<ExistingTranslations::Entry
{
bool operator()(const ExistingTranslations::Entry& lhs, const ExistingTranslations::Entry& rhs) const
{
+ //use a more "natural" sort: ignore case and diacritics
#ifdef FFS_WIN
- //use a more "natural" sort, that is ignore case and diacritics
const int rv = ::CompareString(LOCALE_USER_DEFAULT, //__in LCID Locale,
NORM_IGNORECASE, //__in DWORD dwCmpFlags,
lhs.languageName.c_str(), //__in LPCTSTR lpString1,
@@ -141,8 +145,25 @@ struct LessTranslation : public std::binary_function<ExistingTranslations::Entry
throw std::runtime_error("Error comparing strings!");
else
return rv == CSTR_LESS_THAN; //convert to C-style string compare result
-#else
- return lhs.languageName < rhs.languageName;
+
+#elif defined FFS_LINUX
+ return lhs.languageName.CmpNoCase(rhs.languageName) < 0;
+
+#elif defined FFS_MAC
+ auto allocCFStringRef = [](const wxString& str) -> CFStringRef //output not owned!
+ {
+ return ::CFStringCreateWithCString(nullptr, //CFAllocatorRef alloc,
+ utfCvrtTo<std::string>(str).c_str(), //const char *cStr,
+ kCFStringEncodingUTF8); //CFStringEncoding encoding
+ };
+
+ CFStringRef langL = allocCFStringRef(lhs.languageName);
+ ZEN_ON_SCOPE_EXIT(::CFRelease(langL));
+
+ CFStringRef langR = allocCFStringRef(rhs.languageName);
+ ZEN_ON_SCOPE_EXIT(::CFRelease(langR));
+
+ return::CFStringCompare(langL, langR, kCFCompareLocalized | kCFCompareCaseInsensitive) == kCFCompareLessThan; //no-fail
#endif
}
};
@@ -405,7 +426,7 @@ void zen::setLanguage(int language) //throw FileError
catch (lngfile::ParsingError& e)
{
throw FileError(replaceCpy(replaceCpy(replaceCpy(_("Error parsing file %x, row %y, column %z."),
- L"%x", fmtFileName(toZ(languageFile))),
+ L"%x", fmtFileName(utfCvrtTo<Zstring>(languageFile))),
L"%y", numberTo<std::wstring>(e.row + 1)),
L"%z", numberTo<std::wstring>(e.col + 1)));
}
bgstack15