/* For more information on the Apple locale concept please refer to http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFLocales/Articles/CFLocaleConcepts.html Accordingtothisdocumentationalocaleidentifierhastheformat:language[_country][_variant]* e.g.es_ES_PREEURO->spainpriorEurosupport Note:Thecallingcodeshouldbeabletohandlelocaleswithonlylanguageinformatione.g.'en'forcertain UIlanguagesjustthelanguagecodewillbereturned.
*/
// NOTE: this API is only available with macOS >=10.3. We need to use it because // Apple used non-ISO values on systems <10.2 like "German" for instance but didn't // upgrade those values during upgrade to newer macOS versions. See also #i54337# return CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault, sref);
}
OUStringBuffer aLocaleBuffer("en-US"); // initialize with fallback value
if (sref != nullptr)
{ // split the string into substrings; the first two (if there are two) substrings // are language and country
CFArrayRef subs = CFStringCreateArrayBySeparatingStrings(nullptr, sref, CFSTR("_"));
CFArrayGuard subsGuard(subs);
if (subs != nullptr)
{
aLocaleBuffer.setLength(0); // clear buffer which still contains fallback value
CFStringRef lang = static_cast<CFStringRef>(CFArrayGetValueAtIndex(subs, 0));
OUStringBufferAppendCFString(aLocaleBuffer, lang);
// country also available? Assumption: if the array contains more than one // value the second value is always the country! if (CFArrayGetCount(subs) > 1)
{
aLocaleBuffer.append("-");
CFStringRef country = static_cast<CFStringRef>(CFArrayGetValueAtIndex(subs, 1));
OUStringBufferAppendCFString(aLocaleBuffer, country);
}
}
} return {true, css::uno::Any(aLocaleBuffer.makeStringAndClear())};
}
// locale string have the format lang[_ctry][.encoding][@modifier] // Let LanguageTag handle all conversion, but do a sanity and length check // first. // For the fallback we are only interested in the first two items, so we // handle '.' and '@' as string end for that. for (cp = locale; *cp; cp++)
{ if (*cp == '_' && !uscore)
uscore = cp; if ((*cp == '.' || *cp == '@') && !end)
end = cp; if (!rtl::isAscii(static_cast<unsignedchar>(*cp))) {
SAL_INFO("shell", "locale env var with non-ASCII content"); return {false, {}};
}
}
assert(cp >= locale); if (cp - locale > std::numeric_limits<sal_Int32>::max()) {
SAL_INFO("shell", "locale env var content too long"); return {false, {}};
}
// This is a tad awkward... but the easiest way to obtain what we're // actually interested in. For example this also converts // "ca_ES.UTF-8@valencia" to "ca-ES-valencia". const OString aLocaleStr(locale); const LanguageType nLang = MsLangId::convertUnxByteStringToLanguage( aLocaleStr); if (nLang != LANGUAGE_DONTKNOW)
{ const OUString aLangTagStr( LanguageTag::convertToBcp47( nLang)); return {true, css::uno::Any(aLangTagStr)};
}
// As a fallback, strip encoding and modifier and return just a // language-country combination and let the caller handle unknowns.
OUStringBuffer aLocaleBuffer; if (!end)
end = cp; if( uscore != nullptr )
{
aLocaleBuffer.appendAscii(locale, uscore++ - locale);
aLocaleBuffer.append("-");
aLocaleBuffer.appendAscii(uscore, end - uscore);
} else
{
aLocaleBuffer.appendAscii(locale, end - locale);
}
css::beans::Optional<css::uno::Any> LocaleBackend::getSystemLocale()
{ // note: the implementation differs from getLocale() only on Windows #ifdefined(_WIN32) return ImplGetLocale( GetSystemDefaultLCID() ); #else return getLocale(); #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.