本文整理汇总了C++中Locale::getCountry方法的典型用法代码示例。如果您正苦于以下问题:C++ Locale::getCountry方法的具体用法?C++ Locale::getCountry怎么用?C++ Locale::getCountry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::getCountry方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strcmp
std::wstring L10n::GetFallbackToAvailableDictLocale(const Locale& locale) const
{
std::wstringstream stream;
std::function<bool(const Locale* const&)> checkLangAndCountry = [&locale](const Locale* const& l) {
return strcmp(locale.getLanguage(), l->getLanguage()) == 0
&& strcmp(locale.getCountry(), l->getCountry()) == 0;
};
if (strcmp(locale.getCountry(), "") != 0
&& std::find_if(availableLocales.begin(), availableLocales.end(), checkLangAndCountry) != availableLocales.end())
{
stream << locale.getLanguage() << L"_" << locale.getCountry();
return stream.str();
}
std::function<bool(const Locale* const&)> checkLang = [&locale](const Locale* const& l) {
return strcmp(locale.getLanguage(), l->getLanguage()) == 0;
};
if (std::find_if(availableLocales.begin(), availableLocales.end(), checkLang) != availableLocales.end())
{
stream << locale.getLanguage();
return stream.str();
}
return L"";
}
示例2: langTypeFromLocale
AlphabeticIndex::ELangType AlphabeticIndex::langTypeFromLocale(const Locale &loc) {
const char *lang = loc.getLanguage();
if (uprv_strcmp(lang, "zh") != 0) {
return kNormal;
}
const char *script = loc.getScript();
if (uprv_strcmp(script, "Hant") == 0) {
return kTraditional;
}
const char *country = loc.getCountry();
if (uprv_strcmp(country, "TW") == 0) {
return kTraditional;
}
return kSimplified;
}
示例3: language
void
QuasarConfig::slotLocaleChange()
{
Locale locale;
if (_locale->currentItem() == 0)
locale = systemLocale;
else
locale = _locales[_locale->currentItem() - 1];
QString localesDir = QuasarClient::localesDir();
QString language(locale.getLanguage());
QString country(locale.getCountry());
bool found = false;
QTranslator translator(0);
if (!country.isEmpty()) {
QString dir = localesDir + "/" + language + "_" + country;
if (translator.load("messages.qm", dir))
found = true;
}
if (!found) {
QString dir = localesDir + "/" + language;
if (translator.load("messages.qm", dir))
found = true;
}
if (!found) {
QString message = tr("Quasar has not been localized for this\n"
"locale so the text of the program will\n"
"not change but the date, time, number,\n"
"currency, and percent should be properly\n"
"localized.");
QMessageBox::warning(this, tr("Warning"), message);
}
// Set default locale for ICU
UErrorCode status = U_ZERO_ERROR;
Locale::setDefault(locale, status);
if (U_FAILURE(status)) {
QString msg = tr("Failed setting locale to %1").arg(locale.getName());
QMessageBox::critical(this, tr("Error"), msg);
}
loadLocales();
setSamples();
}
示例4: getPreferredLanguage
std::string GlobalizationNDK::getPreferredLanguage()
{
Locale loc = Locale::getDefault();
std::string ppslang = readLanguageFromPPS();
if (!ppslang.empty())
loc = Locale::createFromName(ppslang.c_str());
const char* lang = loc.getLanguage();
if (!lang || !strlen(lang)) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::getPreferredLanguage: no language for current locale! Use \"en\" instead.");
lang = "en";
}
const char* country = loc.getCountry();
if (!country || !strlen(country)) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::getPreferredLanguage: no country for current locale! Use \"US\" instead.");
country = "US";
}
return resultInJson(std::string(lang) + "-" + country);
}
示例5:
std::string L10n::GetLocaleCountry(const std::string& locale) const
{
Locale loc = Locale::createCanonical(locale.c_str());
return loc.getCountry();
}
示例6: adjustForUsageAndContext
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
if (locale.isBogus()) {
result.setToBogus();
return result;
}
UnicodeString resultName;
const char* lang = locale.getLanguage();
if (uprv_strlen(lang) == 0) {
lang = "root";
}
const char* script = locale.getScript();
const char* country = locale.getCountry();
const char* variant = locale.getVariant();
UBool hasScript = uprv_strlen(script) > 0;
UBool hasCountry = uprv_strlen(country) > 0;
UBool hasVariant = uprv_strlen(variant) > 0;
if (dialectHandling == ULDN_DIALECT_NAMES) {
char buffer[ULOC_FULLNAME_CAPACITY];
do { // loop construct is so we can break early out of search
if (hasScript && hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
hasCountry = FALSE;
break;
}
}
if (hasScript) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
break;
}
}
if (hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasCountry = FALSE;
break;
}
}
} while (FALSE);
}
if (resultName.isBogus() || resultName.isEmpty()) {
localeIdName(lang, resultName);
}
UnicodeString resultRemainder;
UnicodeString temp;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
resultRemainder.append(scriptDisplayName(script, temp, TRUE));
}
if (hasCountry) {
appendWithSep(resultRemainder, regionDisplayName(country, temp, TRUE));
}
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp, TRUE));
}
resultRemainder.findAndReplace(formatOpenParen, formatReplaceOpenParen);
resultRemainder.findAndReplace(formatCloseParen, formatReplaceCloseParen);
LocalPointer<StringEnumeration> e(locale.createKeywords(status));
if (e.isValid() && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
if (U_FAILURE(status)) {
return result;
}
keyDisplayName(key, temp, TRUE);
temp.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp.findAndReplace(formatCloseParen, formatReplaceCloseParen);
keyValueDisplayName(key, value, temp2, TRUE);
temp2.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp2.findAndReplace(formatCloseParen, formatReplaceCloseParen);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
keyTypeFormat.format(temp, temp2, temp3, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((UChar)0x3d /* = */)
.append(temp2);
}
}
}
//.........这里部分代码省略.........
示例7: rpat
void
TZGNCore::initialize(const Locale& locale, UErrorCode& status) {
if (U_FAILURE(status)) {
return;
}
// TimeZoneNames
fTimeZoneNames = TimeZoneNames::createInstance(locale, status);
if (U_FAILURE(status)) {
return;
}
// Initialize format patterns
UnicodeString rpat(TRUE, gDefRegionPattern, -1);
UnicodeString fpat(TRUE, gDefFallbackPattern, -1);
UErrorCode tmpsts = U_ZERO_ERROR; // OK with fallback warning..
UResourceBundle *zoneStrings = ures_open(U_ICUDATA_ZONE, locale.getName(), &tmpsts);
zoneStrings = ures_getByKeyWithFallback(zoneStrings, gZoneStrings, zoneStrings, &tmpsts);
if (U_SUCCESS(tmpsts)) {
const UChar *regionPattern = ures_getStringByKeyWithFallback(zoneStrings, gRegionFormatTag, NULL, &tmpsts);
if (U_SUCCESS(tmpsts) && u_strlen(regionPattern) > 0) {
rpat.setTo(regionPattern, -1);
}
tmpsts = U_ZERO_ERROR;
const UChar *fallbackPattern = ures_getStringByKeyWithFallback(zoneStrings, gFallbackFormatTag, NULL, &tmpsts);
if (U_SUCCESS(tmpsts) && u_strlen(fallbackPattern) > 0) {
fpat.setTo(fallbackPattern, -1);
}
}
ures_close(zoneStrings);
fRegionFormat.applyPatternMinMaxArguments(rpat, 1, 1, status);
fFallbackFormat.applyPatternMinMaxArguments(fpat, 2, 2, status);
if (U_FAILURE(status)) {
cleanup();
return;
}
// locale display names
fLocaleDisplayNames = LocaleDisplayNames::createInstance(locale);
// hash table for names - no key/value deleters
fLocationNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
if (U_FAILURE(status)) {
cleanup();
return;
}
fPartialLocationNamesMap = uhash_open(hashPartialLocationKey, comparePartialLocationKey, NULL, &status);
if (U_FAILURE(status)) {
cleanup();
return;
}
uhash_setKeyDeleter(fPartialLocationNamesMap, uprv_free);
// no value deleter
// target region
const char* region = fLocale.getCountry();
int32_t regionLen = uprv_strlen(region);
if (regionLen == 0) {
char loc[ULOC_FULLNAME_CAPACITY];
uloc_addLikelySubtags(fLocale.getName(), loc, sizeof(loc), &status);
regionLen = uloc_getCountry(loc, fTargetRegion, sizeof(fTargetRegion), &status);
if (U_SUCCESS(status)) {
fTargetRegion[regionLen] = 0;
} else {
cleanup();
return;
}
} else if (regionLen < (int32_t)sizeof(fTargetRegion)) {
uprv_strcpy(fTargetRegion, region);
} else {
fTargetRegion[0] = 0;
}
// preload generic names for the default zone
TimeZone *tz = TimeZone::createDefault();
const UChar *tzID = ZoneMeta::getCanonicalCLDRID(*tz);
if (tzID != NULL) {
loadStrings(UnicodeString(TRUE, tzID, -1));
}
delete tz;
}
示例8: getBundle
ResourceBundlePtr ResourceBundle::getBundle(const String& baseName,
const Locale& locale)
{
String bundleName;
istream * bundleStream;
PropertyResourceBundlePtr resourceBundle, previous;
std::vector<String> bundlesNames;
if (!locale.getVariant().empty())
{
bundlesNames.push_back(baseName + _T("_") +
locale.getLanguage() + _T("_") +
locale.getCountry() + _T("_") +
locale.getVariant());
}
if (!locale.getCountry().empty())
{
bundlesNames.push_back(baseName + _T("_") +
locale.getLanguage() + _T("_") +
locale.getCountry());
}
if (!locale.getLanguage().empty())
{
bundlesNames.push_back(baseName + _T("_") +
locale.getLanguage());
}
bundlesNames.push_back(baseName);
for (std::vector<String>::iterator it = bundlesNames.begin();
it != bundlesNames.end(); it++)
{
bundleName = *it;
PropertyResourceBundlePtr current;
try
{
const Class& classObj = Loader::loadClass(bundleName);
current = classObj.newInstance();
}
catch(ClassNotFoundException&)
{
current = 0;
}
if (current == 0)
{
bundleStream =
Loader::getResourceAsStream(bundleName + _T(".properties"));
if (bundleStream == 0)
{
continue;
}
}
try
{
current = new PropertyResourceBundle(*bundleStream);
}
catch(Exception&)
{
delete bundleStream;
bundleStream = 0;
throw;
}
delete bundleStream;
bundleStream = 0;
if (resourceBundle == 0)
{
resourceBundle = current;
previous = current;
}
else
{
previous->setParent(current);
previous = current;
}
}
if (resourceBundle == 0)
{
throw MissingResourceException();
}
return resourceBundle;
}
示例9: ncat
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
UnicodeString resultName;
const char* lang = locale.getLanguage();
if (uprv_strlen(lang) == 0) {
lang = "root";
}
const char* script = locale.getScript();
const char* country = locale.getCountry();
const char* variant = locale.getVariant();
UBool hasScript = uprv_strlen(script) > 0;
UBool hasCountry = uprv_strlen(country) > 0;
UBool hasVariant = uprv_strlen(variant) > 0;
if (dialectHandling == ULDN_DIALECT_NAMES) {
char buffer[ULOC_FULLNAME_CAPACITY];
do { // loop construct is so we can break early out of search
if (hasScript && hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
hasCountry = FALSE;
break;
}
}
if (hasScript) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
break;
}
}
if (hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasCountry = FALSE;
break;
}
}
} while (FALSE);
}
if (resultName.isBogus() || resultName.isEmpty()) {
localeIdName(lang, resultName);
}
UnicodeString resultRemainder;
UnicodeString temp;
StringEnumeration *e = NULL;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
resultRemainder.append(scriptDisplayName(script, temp));
}
if (hasCountry) {
appendWithSep(resultRemainder, regionDisplayName(country, temp));
}
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp));
}
e = locale.createKeywords(status);
if (e && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
keyDisplayName(key, temp);
keyValueDisplayName(key, value, temp2);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
Formattable data[] = {
temp,
temp2
};
FieldPosition fpos;
status = U_ZERO_ERROR;
keyTypeFormat->format(data, 2, temp3, fpos, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((UChar)0x3d /* = */)
.append(temp2);
}
}
delete e;
}
if (!resultRemainder.isEmpty()) {
Formattable data[] = {
resultName,
resultRemainder
//.........这里部分代码省略.........