void CollationServiceTest::TestSeparateTree() { UErrorCode ec = U_ZERO_ERROR; StringEnumeration *iter = Collator::getKeywords(ec); if (!assertTrue("getKeywords != NULL", iter!=NULL)) return; if (!assertSuccess("getKeywords", ec)) return; checkStringEnumeration("getKeywords", *iter, KW, KW_COUNT); delete iter; iter = Collator::getKeywordValues(KW[0], ec); if (!assertTrue("getKeywordValues != NULL", iter!=NULL, FALSE, TRUE)) return; if (!assertSuccess("getKeywordValues", ec)) return; checkStringEnumeration("getKeywordValues", *iter, KWVAL, KWVAL_COUNT); delete iter; UBool isAvailable; Locale equiv = Collator::getFunctionalEquivalent("collation", Locale::createFromName("de"), isAvailable, ec); assertSuccess("getFunctionalEquivalent", ec); assertEquals("getFunctionalEquivalent(de)", "de", equiv.getName()); assertTrue("getFunctionalEquivalent(de).isAvailable==TRUE", isAvailable == TRUE); equiv = Collator::getFunctionalEquivalent("collation", Locale::createFromName("de_DE"), isAvailable, ec); assertSuccess("getFunctionalEquivalent", ec); assertEquals("getFunctionalEquivalent(de_DE)", "de", equiv.getName()); assertTrue("getFunctionalEquivalent(de_DE).isAvailable==TRUE", isAvailable == TRUE); }
void ResourceBundleTest::TestGetLocaleByType(void) { const struct { const char *requestedLocale; const char *resourceKey; const char *validLocale; const char *actualLocale; } test[] = { { "te_IN_BLAH", "string_only_in_te_IN", "te_IN", "te_IN" }, { "te_IN_BLAH", "string_only_in_te", "te_IN", "te" }, { "te_IN_BLAH", "string_only_in_Root", "te_IN", "root" }, { "te_IN_BLAH_01234567890_01234567890_01234567890_01234567890_01234567890_01234567890", "array_2d_only_in_Root", "te_IN", "root" }, { "te_IN_BLAH@currency=euro", "array_2d_only_in_te_IN", "te_IN", "te_IN" }, { "te_IN_BLAH@calendar=thai;collation=phonebook", "array_2d_only_in_te", "te_IN", "te" } }; UErrorCode status = U_ZERO_ERROR; const char* testdatapath = loadTestData(status); int32_t i = 0; Locale locale; if(U_FAILURE(status)) { dataerrln("Could not load testdata.dat %s\n", u_errorName(status)); return; } for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) { ResourceBundle rb(testdatapath, test[i].requestedLocale, status); if(U_FAILURE(status)) { err("Could not open resource bundle %s (error %s)\n", test[i].requestedLocale, u_errorName(status)); status = U_ZERO_ERROR; continue; } ResourceBundle res = rb.get(test[i].resourceKey, status); if(U_FAILURE(status)) { err("Couldn't find the key %s. Error: %s\n", test[i].resourceKey, u_errorName(status)); status = U_ZERO_ERROR; continue; } locale = res.getLocale(ULOC_REQUESTED_LOCALE, status); if(locale != Locale::getDefault()) { err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } locale = res.getLocale(ULOC_VALID_LOCALE, status); if(strcmp(locale.getName(), test[i].validLocale) != 0) { err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } locale = res.getLocale(ULOC_ACTUAL_LOCALE, status); if(strcmp(locale.getName(), test[i].actualLocale) != 0) { err("Expected actual locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } } }
virtual UObject* create(const ICUServiceKey& key, const ICUService* /*service*/, UErrorCode& status) const { LocaleKey &lkey = (LocaleKey&)key; Locale loc; lkey.currentLocale(loc); #ifdef U_DEBUG_CALSVC fprintf(stderr, "DefaultCalendar factory %p: looking up %s\n", this, (const char*)loc.getName()); #endif UErrorCode resStatus = U_ZERO_ERROR; UResourceBundle *rb = ures_open(NULL, (const char*)loc.getName(), &resStatus); #ifdef U_DEBUG_CALSVC fprintf(stderr, "... ures_open -> %s\n", u_errorName(resStatus)); #endif if(U_FAILURE(resStatus) || (resStatus == U_USING_DEFAULT_WARNING) || (resStatus==U_USING_FALLBACK_WARNING)) { //Don't want to handle fallback data. ures_close(rb); status = resStatus; // propagate err back to caller #ifdef U_DEBUG_CALSVC fprintf(stderr, "... exitting (NULL)\n"); #endif return NULL; } int32_t len = 0; UnicodeString myString = ures_getUnicodeStringByKey(rb, Calendar::kDefaultCalendar, &status); #ifdef U_DEBUG_CALSVC UErrorCode debugStatus = U_ZERO_ERROR; const UChar *defCal = ures_getStringByKey(rb, Calendar::kDefaultCalendar, &len, &debugStatus); fprintf(stderr, "... get string(%d) -> %s\n", len, u_errorName(debugStatus)); #endif ures_close(rb); if(U_FAILURE(status)) { return NULL; } #ifdef U_DEBUG_CALSVC { char defCalStr[200]; if(len > 199) { len = 199; } u_UCharsToChars(defCal, defCalStr, len); defCalStr[len]=0; fprintf(stderr, "DefaultCalendarFactory: looked up %s, got DefaultCalendar= %s\n", (const char*)loc.getName(), defCalStr); } #endif return myString.clone(); }
bool L10n::SaveLocale(const Locale& locale) const { if (!ValidateLocale(locale)) return false; g_ConfigDB.SetValueString(CFG_USER, "locale", locale.getName()); g_ConfigDB.WriteValueToFile(CFG_USER, "locale", locale.getName()); return true; }
void WelcomeDialog::slotLocaleChanged() { bool firstTime = (_locale->count() == 0); int index = _locale->currentItem(); QString systemLocaleName = systemLocale.getName(); // Set default locale for ICU if (!firstTime) { Locale locale = _locales[index]; 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); } } _locale->clear(); for (int32_t i = 0; i < _localesCnt; ++i) { UnicodeString uname; _locales[i].getDisplayName(uname); QString name = convertToQt(uname); _locale->insertItem(name); if (firstTime && _locales[i].getName() == systemLocaleName) { firstTime = false; index = _locale->count() - 1; } } QString localeMsg = tr("Select the locale you are using. This will " "control the language\nused for messages " "and the format of dates, money, ...\n\n"); QString serverMsg = tr("Select the server to connect to. The " "default is \"localhost\"\nwhich will connect " "to a server on your own computer.\n\n"); _locale->setCurrentItem(index); _localeBox->setTitle(tr("Locale")); _localeMsg->setText(localeMsg); _localeLabel->setText(tr("Locale:")); _serverBox->setTitle(tr("Server")); _serverMsg->setText(serverMsg); _serverLabel->setText(tr("Server:")); _ok->setText(tr("OK")); _cancel->setText(tr("Cancel")); }
void ResourceBundle::constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error) { if (path.isEmpty()) { fResource = ures_open(NULL, locale.getName(), &error); } else { UnicodeString nullTerminatedPath(path); nullTerminatedPath.append((UChar)0); fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error); } }
StringSearch::StringSearch(const UnicodeString &pattern, const UnicodeString &text, const Locale &locale, BreakIterator *breakiter, UErrorCode &status) : SearchIterator(text, breakiter), m_pattern_(pattern) { if (U_FAILURE(status)) { m_strsrch_ = NULL; return; } m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(), m_text_.getBuffer(), m_text_.length(), locale.getName(), (UBreakIterator *)breakiter, &status); uprv_free(m_search_); m_search_ = NULL; if (U_SUCCESS(status)) { // m_search_ has been created by the base SearchIterator class m_search_ = m_strsrch_->search; } }
void CompactData::populate(const Locale &locale, const char *nsName, CompactStyle compactStyle, CompactType compactType, UErrorCode &status) { CompactDataSink sink(*this); LocalUResourceBundlePointer rb(ures_open(nullptr, locale.getName(), &status)); if (U_FAILURE(status)) { return; } bool nsIsLatn = strcmp(nsName, "latn") == 0; bool compactIsShort = compactStyle == CompactStyle::UNUM_SHORT; // Fall back to latn numbering system and/or short compact style. CharString resourceKey; getResourceBundleKey(nsName, compactStyle, compactType, resourceKey, status); UErrorCode localStatus = U_ZERO_ERROR; ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus); if (isEmpty && !nsIsLatn) { getResourceBundleKey("latn", compactStyle, compactType, resourceKey, status); localStatus = U_ZERO_ERROR; ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus); } if (isEmpty && !compactIsShort) { getResourceBundleKey(nsName, CompactStyle::UNUM_SHORT, compactType, resourceKey, status); localStatus = U_ZERO_ERROR; ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus); } if (isEmpty && !nsIsLatn && !compactIsShort) { getResourceBundleKey("latn", CompactStyle::UNUM_SHORT, compactType, resourceKey, status); localStatus = U_ZERO_ERROR; ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus); } // The last fallback should be guaranteed to return data. if (isEmpty) { status = U_INTERNAL_PROGRAM_ERROR; } }
NumberingSystem* U_EXPORT2 NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) { char buffer[ULOC_KEYWORDS_CAPACITY]; int32_t count = inLocale.getKeywordValue("numbers",buffer, sizeof(buffer),status); if ( count > 0 ) { // @numbers keyword was specified in the locale buffer[count] = '\0'; // Make sure it is null terminated. return NumberingSystem::createInstanceByName(buffer,status); } else { // Find the default numbering system for this locale. LocalUResourceBundlePointer resource(ures_open(NULL, inLocale.getName(), &status)); if (U_FAILURE(status)) { status = U_USING_FALLBACK_WARNING; NumberingSystem *ns = new NumberingSystem(); return ns; } const UChar *defaultNSName = ures_getStringByKeyWithFallback(resource.getAlias(), gDefaultNumberingSystem, &count, &status); if (U_FAILURE(status)) { return NULL; } if ( count > 0 && count < ULOC_KEYWORDS_CAPACITY ) { // Default numbering system found u_UCharsToChars(defaultNSName,buffer,count); buffer[count] = '\0'; // Make sure it is null terminated. return NumberingSystem::createInstanceByName(buffer,status); } else { status = U_USING_FALLBACK_WARNING; NumberingSystem *ns = new NumberingSystem(); return ns; } } }
StringSearch::StringSearch(const UnicodeString &pattern, CharacterIterator &text, const Locale &locale, BreakIterator *breakiter, UErrorCode &status) : SearchIterator(text, breakiter), m_collator_(), m_pattern_(pattern) { if (U_FAILURE(status)) { m_strsrch_ = NULL; return; } m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(), m_text_.getBuffer(), m_text_.length(), locale.getName(), (UBreakIterator *)breakiter, &status); uprv_free(m_search_); m_search_ = NULL; if (U_SUCCESS(status)) { int32_t length; const UChar *rules = ucol_getRules(m_strsrch_->collator, &length); m_collation_rules_.setTo(rules, length); m_collator_.setUCollator((UCollator *)m_strsrch_->collator, &m_collation_rules_); // m_search_ has been created by the base SearchIterator class m_search_ = m_strsrch_->search; } }
GLUE_SYM ( DateFormat ) :: create(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char *locale, const UChar *tzID, int32_t tzIDLength, const UChar *pattern, int32_t patternLength, UErrorCode *status, const Locale &loc, const char */*ver*/) { // TODO: save version //char locBuf[200]; //char kwvBuf[200]; UDateFormat * uc = OICU_udat_open( timeStyle, dateStyle, locale, tzID, tzIDLength, pattern, patternLength, status); if(U_FAILURE(*status)) return NULL; // TODO: ERR? DateFormat *c = new GLUE_SYM( DateFormat ) ( uc ); #if DATE_FE_DEBUG fprintf(stderr, "VCF " ICUGLUE_VER_STR " udat_open=%s ->> %p\n", loc.getName(), (void*)c); #endif return c; }
U_CFUNC PHP_FUNCTION(breakiter_get_locale) { zend_long locale_type; BREAKITER_METHOD_INIT_VARS; object = getThis(); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &locale_type) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "breakiter_get_locale: bad arguments", 0); RETURN_FALSE; } if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "breakiter_get_locale: invalid locale type", 0); RETURN_FALSE; } BREAKITER_METHOD_FETCH_OBJECT; Locale locale = bio->biter->getLocale((ULocDataLocaleType)locale_type, BREAKITER_ERROR_CODE(bio)); INTL_METHOD_CHECK_STATUS(bio, "breakiter_get_locale: Call to ICU method has failed"); RETURN_STRING(locale.getName()); }
U_CFUNC PHP_FUNCTION(intlcal_get_locale) { zend_long locale_type; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &locale_type) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_locale: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_locale: invalid locale type", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; Locale locale = co->ucal->getLocale((ULocDataLocaleType)locale_type, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_get_locale: Call to ICU method has failed"); RETURN_STRING(locale.getName()); }
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale, UErrorCode& status) { if (U_FAILURE(status)) return 0; #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc; Collator *result = (Collator*)gService->get(desiredLocale, &actualLoc, status); // Ugly Hack Alert! If the returned locale is empty (not root, // but empty -- getName() == "") then that means the service // returned a default object, not a "real" service object. In // that case, the locale metadata (valid & actual) is setup // correctly already, and we don't want to overwrite it. (TODO // remove in 3.0) [aliu] if (*actualLoc.getName() != 0) { result->setLocales(desiredLocale, actualLoc, actualLoc); } return result; } #endif return makeInstance(desiredLocale, status); }
U_CDECL_END U_NAMESPACE_BEGIN Locale *locale_set_default_internal(const char *id, UErrorCode& status) { // Synchronize this entire function. Mutex lock(&gDefaultLocaleMutex); UBool canonicalize = FALSE; // If given a NULL string for the locale id, grab the default // name from the system. // (Different from most other locale APIs, where a null name means use // the current ICU default locale.) if (id == NULL) { id = uprv_getDefaultLocaleID(); // This function not thread safe? TODO: verify. canonicalize = TRUE; // always canonicalize host ID } char localeNameBuf[512]; if (canonicalize) { uloc_canonicalize(id, localeNameBuf, sizeof(localeNameBuf)-1, &status); } else { uloc_getName(id, localeNameBuf, sizeof(localeNameBuf)-1, &status); } localeNameBuf[sizeof(localeNameBuf)-1] = 0; // Force null termination in event of // a long name filling the buffer. // (long names are truncated.) // if (U_FAILURE(status)) { return gDefaultLocale; } if (gDefaultLocalesHashT == NULL) { gDefaultLocalesHashT = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status); if (U_FAILURE(status)) { return gDefaultLocale; } uhash_setValueDeleter(gDefaultLocalesHashT, deleteLocale); ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup); } Locale *newDefault = (Locale *)uhash_get(gDefaultLocalesHashT, localeNameBuf); if (newDefault == NULL) { newDefault = new Locale(Locale::eBOGUS); if (newDefault == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return gDefaultLocale; } newDefault->init(localeNameBuf, FALSE); uhash_put(gDefaultLocalesHashT, (char*) newDefault->getName(), newDefault, &status); if (U_FAILURE(status)) { return gDefaultLocale; } } gDefaultLocale = newDefault; return gDefaultLocale; }
NumberingSystem* U_EXPORT2 NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) { if (U_FAILURE(status)) { return NULL; } UBool nsResolved = TRUE; UBool usingFallback = FALSE; char buffer[ULOC_KEYWORDS_CAPACITY]; int32_t count = inLocale.getKeywordValue("numbers",buffer, sizeof(buffer),status); if ( count > 0 ) { // @numbers keyword was specified in the locale buffer[count] = '\0'; // Make sure it is null terminated. if ( !uprv_strcmp(buffer,gDefault) || !uprv_strcmp(buffer,gNative) || !uprv_strcmp(buffer,gTraditional) || !uprv_strcmp(buffer,gFinance)) { nsResolved = FALSE; } } else { uprv_strcpy(buffer,gDefault); nsResolved = FALSE; } if (!nsResolved) { // Resolve the numbering system ( default, native, traditional or finance ) into a "real" numbering system UErrorCode localStatus = U_ZERO_ERROR; UResourceBundle *resource = ures_open(NULL, inLocale.getName(), &localStatus); UResourceBundle *numberElementsRes = ures_getByKey(resource,gNumberElements,NULL,&localStatus); while (!nsResolved) { localStatus = U_ZERO_ERROR; count = 0; const UChar *nsName = ures_getStringByKeyWithFallback(numberElementsRes, buffer, &count, &localStatus); if ( count > 0 && count < ULOC_KEYWORDS_CAPACITY ) { // numbering system found u_UCharsToChars(nsName,buffer,count); buffer[count] = '\0'; // Make sure it is null terminated. nsResolved = TRUE; } if (!nsResolved) { // Fallback behavior per TR35 - traditional falls back to native, finance and native fall back to default if (!uprv_strcmp(buffer,gNative) || !uprv_strcmp(buffer,gFinance)) { uprv_strcpy(buffer,gDefault); } else if (!uprv_strcmp(buffer,gTraditional)) { uprv_strcpy(buffer,gNative); } else { // If we get here we couldn't find even the default numbering system usingFallback = TRUE; nsResolved = TRUE; } } } ures_close(numberElementsRes); ures_close(resource); } if (usingFallback) { status = U_USING_FALLBACK_WARNING; NumberingSystem *ns = new NumberingSystem(); return ns; } else { return NumberingSystem::createInstanceByName(buffer,status); } }
// initCDFLocaleData initializes result with data from CLDR. // inLocale is the locale, the CLDR data is stored in result. // We load the UNUM_SHORT and UNUM_LONG data looking first in local numbering // system and not including root locale in fallback. Next we try in the latn // numbering system where we fallback all the way to root. If we don't find // UNUM_SHORT data in these three places, we report an error. If we find // UNUM_SHORT data before finding UNUM_LONG data we make UNUM_LONG data fall // back to UNUM_SHORT data. static void initCDFLocaleData(const Locale& inLocale, CDFLocaleData* result, UErrorCode& status) { LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(inLocale, status)); if (U_FAILURE(status)) { return; } const char* numberingSystemName = ns->getName(); UResourceBundle* rb = ures_open(NULL, inLocale.getName(), &status); rb = ures_getByKeyWithFallback(rb, gNumberElementsTag, rb, &status); if (U_FAILURE(status)) { ures_close(rb); return; } UResourceBundle* shortDataFillIn = NULL; UResourceBundle* longDataFillIn = NULL; UResourceBundle* shortData = NULL; UResourceBundle* longData = NULL; if (uprv_strcmp(numberingSystemName, gLatnTag) != 0) { LocalUResourceBundlePointer localResource( tryGetByKeyWithFallback(rb, numberingSystemName, NULL, NOT_ROOT, status)); shortData = tryGetDecimalFallback( localResource.getAlias(), gPatternsShort, &shortDataFillIn, NOT_ROOT, status); longData = tryGetDecimalFallback( localResource.getAlias(), gPatternsLong, &longDataFillIn, NOT_ROOT, status); } if (U_FAILURE(status)) { ures_close(shortDataFillIn); ures_close(longDataFillIn); ures_close(rb); return; } // If we haven't found UNUM_SHORT look in latn numbering system. We must // succeed at finding UNUM_SHORT here. if (shortData == NULL) { LocalUResourceBundlePointer latnResource(tryGetByKeyWithFallback(rb, gLatnTag, NULL, MUST, status)); shortData = tryGetDecimalFallback(latnResource.getAlias(), gPatternsShort, &shortDataFillIn, MUST, status); if (longData == NULL) { longData = tryGetDecimalFallback(latnResource.getAlias(), gPatternsLong, &longDataFillIn, ANY, status); if (longData != NULL && isRoot(longData, status) && !isRoot(shortData, status)) { longData = NULL; } } } initCDFLocaleStyleData(shortData, &result->shortData, status); ures_close(shortDataFillIn); if (U_FAILURE(status)) { ures_close(longDataFillIn); ures_close(rb); } if (longData == NULL) { result->longData.setToBogus(); } else { initCDFLocaleStyleData(longData, &result->longData, status); } ures_close(longDataFillIn); ures_close(rb); }
StringEnumeration* U_EXPORT2 Collator::getKeywordValuesForLocale(const char* key, const Locale& locale, UBool commonlyUsed, UErrorCode& status) { return UStringEnumeration::fromUEnumeration( ucol_getKeywordValuesForLocale( key, locale.getName(), commonlyUsed, &status), status); }
void RuleBasedCollator::setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale) { checkOwned(); char* rloc = uprv_strdup(requestedLocale.getName()); if (rloc) { char* vloc = uprv_strdup(validLocale.getName()); if (vloc) { char* aloc = uprv_strdup(actualLocale.getName()); if (aloc) { ucol_setReqValidLocales(ucollator, rloc, vloc, aloc); return; } uprv_free(vloc); } uprv_free(rloc); } }
void RuleBasedCollator::setLocales(const Locale& requestedLocale, const Locale& validLocale) { checkOwned(); size_t rlen = uprv_strlen(requestedLocale.getName()); char* rloc = (char *)uprv_malloc((rlen+1)*sizeof(char)); if (rloc) { uprv_strcpy(rloc, requestedLocale.getName()); size_t vlen = uprv_strlen(validLocale.getName()); char* vloc = (char*)uprv_malloc((vlen+1)*sizeof(char)); if (vloc) { uprv_strcpy(vloc, validLocale.getName()); ucol_setReqValidLocales(ucollator, rloc, vloc); return; } uprv_free(rloc); } }
static void load(const Locale& inLocale, CDFLocaleData* result, UErrorCode& status) { LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(inLocale, status)); if (U_FAILURE(status)) { return; } const char* nsName = ns->getName(); LocalUResourceBundlePointer resource(ures_open(NULL, inLocale.getName(), &status)); if (U_FAILURE(status)) { return; } CmptDecDataSink sink(*result); sink.isFallback = FALSE; // First load the number elements data if nsName is not Latin. if (uprv_strcmp(nsName, gLatnTag) != 0) { sink.isLatin = FALSE; CharString path; path.append(gNumberElementsTag, status) .append('/', status) .append(nsName, status); ures_getAllItemsWithFallback(resource.getAlias(), path.data(), sink, status); if (status == U_MISSING_RESOURCE_ERROR) { // Silently ignore and use Latin status = U_ZERO_ERROR; } else if (U_FAILURE(status)) { return; } sink.isFallback = TRUE; } // Now load Latin. sink.isLatin = TRUE; ures_getAllItemsWithFallback(resource.getAlias(), gLatnPath, sink, status); if (U_FAILURE(status)) return; // If longData is empty, default it to be equal to shortData if (result->longData.isEmpty()) { result->longData.setToBogus(); } // Check for "other" variants in each of the three data classes, and resolve missing elements. if (!result->longData.isBogus()) { checkForOtherVariants(&result->longData, status); if (U_FAILURE(status)) return; fillInMissing(&result->longData); } checkForOtherVariants(&result->shortData, status); if (U_FAILURE(status)) return; fillInMissing(&result->shortData); // TODO: Enable this statement when currency support is added // checkForOtherVariants(&result->shortCurrencyData, status); // if (U_FAILURE(status)) return; // fillInMissing(&result->shortCurrencyData); }
void AlphabeticIndex::addIndexExemplars(const Locale &locale, UErrorCode &status) { LocalULocaleDataPointer uld(ulocdata_open(locale.getName(), &status)); if (U_FAILURE(status)) { return; } UnicodeSet exemplars; ulocdata_getExemplarSet(uld.getAlias(), exemplars.toUSet(), 0, ULOCDATA_ES_INDEX, &status); if (U_SUCCESS(status)) { initialLabels_->addAll(exemplars); return; } status = U_ZERO_ERROR; // Clear out U_MISSING_RESOURCE_ERROR // The locale data did not include explicit Index characters. // Synthesize a set of them from the locale's standard exemplar characters. ulocdata_getExemplarSet(uld.getAlias(), exemplars.toUSet(), 0, ULOCDATA_ES_STANDARD, &status); if (U_FAILURE(status)) { return; } // question: should we add auxiliary exemplars? if (exemplars.containsSome(0x61, 0x7A) /* a-z */ || exemplars.size() == 0) { exemplars.add(0x61, 0x7A); } if (exemplars.containsSome(0xAC00, 0xD7A3)) { // Hangul syllables // cut down to small list exemplars.remove(0xAC00, 0xD7A3). add(0xAC00).add(0xB098).add(0xB2E4).add(0xB77C). add(0xB9C8).add(0xBC14).add(0xC0AC).add(0xC544). add(0xC790).add(0xCC28).add(0xCE74).add(0xD0C0). add(0xD30C).add(0xD558); } if (exemplars.containsSome(0x1200, 0x137F)) { // Ethiopic block // cut down to small list // make use of the fact that Ethiopic is allocated in 8's, where // the base is 0 mod 8. UnicodeSet ethiopic( UNICODE_STRING_SIMPLE("[[:Block=Ethiopic:]&[:Script=Ethiopic:]]"), status); UnicodeSetIterator it(ethiopic); while (it.next() && !it.isString()) { if ((it.getCodepoint() & 0x7) != 0) { exemplars.remove(it.getCodepoint()); } } } // Upper-case any that aren't already so. // (We only do this for synthesized index characters.) UnicodeSetIterator it(exemplars); UnicodeString upperC; while (it.next()) { const UnicodeString &exemplarC = it.getString(); upperC = exemplarC; upperC.toUpper(locale); initialLabels_->add(upperC); } }
QString WelcomeDialog::locale() const { // Return the locale they have picked unless its the system one // in which case just return "" so that Quasar will continue to // use the system locale. QString name = _locales[_locale->currentItem()].getName(); if (name == systemLocale.getName()) return ""; return name; }
void RelativeDateTimeFormatterTest::RunTest( const Locale& locale, const WithoutQuantityExpected* expectedResults, int32_t expectedResultLength) { UErrorCode status = U_ZERO_ERROR; RelativeDateTimeFormatter fmt(locale, status); if (U_FAILURE(status)) { dataerrln("Unable to create format object - %s", u_errorName(status)); return; } RunTest(fmt, expectedResults, expectedResultLength, locale.getName()); }
Locale U_EXPORT2 Collator::getFunctionalEquivalent(const char* keyword, const Locale& locale, UBool& isAvailable, UErrorCode& status) { // This is a wrapper over ucol_getFunctionalEquivalent char loc[ULOC_FULLNAME_CAPACITY]; /*int32_t len =*/ ucol_getFunctionalEquivalent(loc, sizeof(loc), keyword, locale.getName(), &isAvailable, &status); if (U_FAILURE(status)) { *loc = 0; // root } return Locale::createFromName(loc); }
StringEnumeration* U_EXPORT2 Collator::getKeywordValuesForLocale(const char* key, const Locale& locale, UBool commonlyUsed, UErrorCode& status) { // This is a wrapper over ucol_getKeywordValuesForLocale UEnumeration *uenum = ucol_getKeywordValuesForLocale(key, locale.getName(), commonlyUsed, &status); if (U_FAILURE(status)) { uenum_close(uenum); return NULL; } return new UStringEnumeration(uenum); }
void IntlCalendarTest::simpleTest(const Locale& loc, const UnicodeString& expect, UDate expectDate, UErrorCode& status) { UnicodeString tmp; UDate d; DateFormat *fmt0 = DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull); logln("Try format/parse of " + (UnicodeString)loc.getName()); DateFormat *fmt2 = DateFormat::createDateInstance(DateFormat::kFull, loc); if(fmt2) { fmt2->format(expectDate, tmp); logln(escape(tmp) + " ( in locale " + loc.getName() + ")"); if(tmp != expect) { errln(UnicodeString("Failed to format " ) + loc.getName() + " expected " + escape(expect) + " got " + escape(tmp) ); } d = fmt2->parse(expect,status); CHECK(status, "Error occured parsing " + UnicodeString(loc.getName())); if(d != expectDate) { fmt2->format(d,tmp); errln(UnicodeString("Failed to parse " ) + escape(expect) + ", " + loc.getName() + " expect " + (double)expectDate + " got " + (double)d + " " + escape(tmp)); logln( "wanted " + escape(fmt0->format(expectDate,tmp.remove())) + " but got " + escape(fmt0->format(d,tmp.remove()))); } delete fmt2; } else { errln((UnicodeString)"Can't create " + loc.getName() + " date instance"); } delete fmt0; }
void CompactDecimalFormatTest::CheckLocale(const Locale& locale, UNumberCompactStyle style, const ExpectedResult* expectedResults, int32_t expectedResultLength) { UErrorCode status = U_ZERO_ERROR; LocalPointer<CompactDecimalFormat> cdf(createCDFInstance(locale, style, status)); if (U_FAILURE(status)) { dataerrln("Unable to create format object - %s", u_errorName(status)); return; } char description[256]; sprintf(description,"%s - %s", locale.getName(), StyleStr(style)); for (int32_t i = 0; i < expectedResultLength; i++) { CheckExpectedResult(cdf.getAlias(), &expectedResults[i], description); } }
UnicodeString & ICUDataTable::get(const char* tableKey, const char* subTableKey, const char* itemKey, UnicodeString &result) const { UErrorCode status = U_ZERO_ERROR; int32_t len = 0; const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(), tableKey, subTableKey, itemKey, &len, &status); if (U_SUCCESS(status) && len > 0) { return result.setTo(s, len); } return result.setTo(UnicodeString(itemKey, -1, US_INV)); }
void Calendar::setWeekCountData(const Locale& desiredLocale, UErrorCode& status) { // Read the week count data from the resource bundle. This should // have the form: // // DateTimeElements:intvector { // 1, // first day of week // 1 // min days in week // } // Both have a range of 1..7 if (U_FAILURE(status)) return; fFirstDayOfWeek = UCAL_SUNDAY; fMinimalDaysInFirstWeek = 1; UResourceBundle *resource = ures_open(NULL, desiredLocale.getName(), &status); // If the resource data doesn't seem to be present at all, then use last-resort // hard-coded data. if (U_FAILURE(status)) { status = U_USING_FALLBACK_WARNING; ures_close(resource); return; } //dateTimeElements = resource.getStringArray(kDateTimeElements, count, status); UResourceBundle *dateTimeElements = ures_getByKey(resource, kDateTimeElements, NULL, &status); if (U_SUCCESS(status)) { int32_t arrLen; const int32_t *dateTimeElementsArr = ures_getIntVector(dateTimeElements, &arrLen, &status); if(U_SUCCESS(status) && arrLen == 2 && 1 <= dateTimeElementsArr[0] && dateTimeElementsArr[0] <= 7 && 1 <= dateTimeElementsArr[1] && dateTimeElementsArr[1] <= 7) { fFirstDayOfWeek = (UCalendarDaysOfWeek)dateTimeElementsArr[0]; fMinimalDaysInFirstWeek = (uint8_t)dateTimeElementsArr[1]; } else { status = U_INVALID_FORMAT_ERROR; } } ures_close(dateTimeElements); ures_close(resource); }