Example #1
0
void
ResourceBundleTest::TestExemplar(){

    int32_t locCount = uloc_countAvailable();
    int32_t locIndex=0;
    int num=0;
    UErrorCode status = U_ZERO_ERROR;
    for(;locIndex<locCount;locIndex++){
        const char* locale = uloc_getAvailable(locIndex);
        UResourceBundle *resb =ures_open(NULL,locale,&status);
        if(U_SUCCESS(status) && status!=U_USING_FALLBACK_WARNING && status!=U_USING_DEFAULT_WARNING){
            int32_t len=0;
            const UChar* strSet = ures_getStringByKey(resb,"ExemplarCharacters",&len,&status);
            UnicodeSet set(strSet,status);
            if(U_FAILURE(status)){
                errln("Could not construct UnicodeSet from pattern for ExemplarCharacters in locale : %s. Error: %s",locale,u_errorName(status));
                status=U_ZERO_ERROR;
            }
            num++;
        }
        ures_close(resb);
    }
    logln("Number of installed locales with exemplar characters that could be tested: %d",num);

}
Example #2
0
static jobjectArray getAvailableLocalesNative(JNIEnv* env, jclass clazz) {
    size_t count = uloc_countAvailable();
    jobjectArray result = env->NewObjectArray(count, string_class, NULL);
    for (size_t i = 0; i < count; ++i) {
        jstring s = env->NewStringUTF(uloc_getAvailable(i));
        env->SetObjectArrayElement(result, i, s);
        env->DeleteLocalRef(s);
    }
    return result;
}
Example #3
0
static void TestAllLocales(void) {
    int32_t idx, dateIdx, timeIdx, localeCount;
    static const UDateFormatStyle style[] = {
        UDAT_FULL, UDAT_LONG, UDAT_MEDIUM, UDAT_SHORT
    };
    localeCount = uloc_countAvailable();
    for (idx = 0; idx < localeCount; idx++) {
        for (dateIdx = 0; dateIdx < (int32_t)(sizeof(style)/sizeof(style[0])); dateIdx++) {
            for (timeIdx = 0; timeIdx < (int32_t)(sizeof(style)/sizeof(style[0])); timeIdx++) {
                UErrorCode status = U_ZERO_ERROR;
                udat_close(udat_open(style[dateIdx], style[timeIdx],
                    uloc_getAvailable(idx), NULL, 0, NULL, 0, &status));
                if (U_FAILURE(status)) {
                    log_err("FAIL: udat_open(%s) failed with (%s) dateIdx=%d, timeIdx=%d\n",
                        uloc_getAvailable(idx), u_errorName(status), dateIdx, timeIdx);
                }
            }
        }
    }
}
void LanguagePage::retranslateUi()
{
    //% "Change Language"
    setTitle(qtTrId("xx_language_title"));
    if (!isContentCreated())
        return;

    disconnect(comboBoxLanguage, SIGNAL(currentIndexChanged(int)),
               this, SLOT(changeLanguage(int)));
    disconnect(comboBoxLcTime, SIGNAL(currentIndexChanged(int)),
               this, SLOT(changeLcTime(int)));
    disconnect(comboBoxLcTimeFormat24h, SIGNAL(currentIndexChanged(int)),
               this, SLOT(changeLcTimeFormat24h(int)));
    disconnect(comboBoxLcCollate, SIGNAL(currentIndexChanged(int)),
               this, SLOT(changeLcCollate(int)));
    disconnect(comboBoxLcNumeric, SIGNAL(currentIndexChanged(int)),
               this, SLOT(changeLcNumeric(int)));
    disconnect(comboBoxLcMonetary, SIGNAL(currentIndexChanged(int)),
               this, SLOT(changeLcMonetary(int)));

    QStringList localeNames;
#ifdef HAVE_ICU
    int numberOfAvailableLocales = uloc_countAvailable();
    for (int i = 0; i < numberOfAvailableLocales; ++i)
        localeNames << QString::fromUtf8(uloc_getAvailable(i));
    localeNames << "no";
    localeNames << "no_NO";
    localeNames << "es_419";
    localeNames << "de@collation=phonebook";
    localeNames << "de_DE@collation=phonebook";
    localeNames << "zh_Hans_CN@collation=pinyin";
    localeNames << "zh_Hans_CN@collation=stroke";
    QStringList localeNamesWithoutScript;
    QRegExp regexp("^([a-z]{2,3}_)([A-Z][a-z]{3,3}_)(.*)$");
    foreach (const QString &localeName, localeNames) {
        if (regexp.indexIn(localeName) == 0) {
            localeNamesWithoutScript <<
                regexp.capturedTexts().at(1) + regexp.capturedTexts().at(3);
        }
    }
    foreach (const QString &localeName, localeNamesWithoutScript)
        localeNames << localeName;
#else
    for (unsigned language = QLocale::C;
         language <= QLocale::LastLanguage;
         language++) {
        foreach (const QLocale::Country &country,
                 QLocale::countriesForLanguage (QLocale::Language(language))) {
            localeNames << QLocale(QLocale::Language(language), country).name();
        }
    }
static jobjectArray getAvailableLocalesNative(JNIEnv* env, jclass clazz) {
    // LOGI("ENTER getAvailableLocalesNative");
    
    int count = uloc_countAvailable();
    
    jobjectArray result = env->NewObjectArray(count, string_class, NULL);

    jstring res;
    const char * string;    
    for(int i = 0; i < count; i++) {
        string = uloc_getAvailable(i);
        res = env->NewStringUTF(string);
        env->SetObjectArrayElement(result, i, res);
        env->DeleteLocalRef(res);
    }

    return result;
}
Example #6
0
// GlobalizationNative_GetLocales gets all locale names and store it in the value buffer
// in case of success, it returns the count of the characters stored in value buffer
// in case of failure, it returns negative number.
// if the input value buffer is null, it returns the length needed to store the
// locale names list.
// if the value is not null, it fills the value with locale names separated by the length
// of each name.
extern "C" int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength)
{
    int32_t totalLength = 0;
    int32_t index = 0;
    int32_t localeCount = uloc_countAvailable();

    if (localeCount <=  0)
        return -1; // failed

    for (int32_t i = 0; i < localeCount; i++)
    {
        const char *pLocaleName = uloc_getAvailable(i);
        if (pLocaleName[0] == 0) // unexpected empty name
            return -2;

        int32_t localeNameLength = strlen(pLocaleName);

        totalLength += localeNameLength + 1; // add 1 for the name length

        if (value != nullptr)
        {
            if (totalLength > valueLength)
                return -3;

            value[index++] = (UChar) localeNameLength;

            for (int j=0; j<localeNameLength; j++)
            {
                if (pLocaleName[j] == '_') // fix the locale name
                {
                    value[index++] = (UChar) '-';
                }
                else
                {
                    value[index++] = (UChar) pLocaleName[j];
                }
            }
        }
    }

    return totalLength;
}
Example #7
0
CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers(void) {
    int32_t locale, localeCount = uloc_countAvailable();
    CFMutableSetRef working = CFSetCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeSetCallBacks);
    for (locale = 0; locale < localeCount; ++locale) {
        const char *localeID = uloc_getAvailable(locale);
        CFStringRef string1 = CFStringCreateWithCString(kCFAllocatorSystemDefault, localeID, kCFStringEncodingASCII);
	CFStringRef string2 = CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorSystemDefault, string1);
	CFSetAddValue(working, string1);
	// do not include canonicalized version as IntlFormats cannot cope with that in its popup
        CFRelease(string1);
        CFRelease(string2);
    }
    CFIndex cnt = CFSetGetCount(working);
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_LINUX || (DEPLOYMENT_TARGET_WINDOWS && __GNUC__)
    STACK_BUFFER_DECL(const void *, buffer, cnt);
#else
    const void* buffer[BUFFER_SIZE];
#endif
    CFSetGetValues(working, buffer);
    CFArrayRef result = CFArrayCreate(kCFAllocatorSystemDefault, buffer, cnt, &kCFTypeArrayCallBacks);
    CFRelease(working);
    return result;
}
Example #8
0
U_CAPI const char* U_EXPORT2
udat_getAvailable(int32_t index)
{
    return uloc_getAvailable(index);
}
Example #9
0
static void TestCurrencyKeywords(void)
{
    static const char * const currencies[] = {
        "ADD", "ADP", "AED", "AFA", "AFN", "AIF", "ALK", "ALL", "ALV", "ALX", "AMD",
        "ANG", "AOA", "AOK", "AON", "AOR", "AOS", "ARA", "ARM", "ARP", "ARS", "ATS",
        "AUD", "AUP", "AWG", "AZM", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF",
        "BEL", "BGL", "BGM", "BGN", "BGO", "BGX", "BHD", "BIF", "BMD", "BMP", "BND",
        "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ",
        "BSD", "BSP", "BTN", "BTR", "BUK", "BUR", "BWP", "BYB", "BYL", "BYR", "BZD",
        "BZH", "CAD", "CDF", "CDG", "CDL", "CFF", "CHF", "CKD", "CLC", "CLE", "CLF",
        "CLP", "CMF", "CNP", "CNX", "CNY", "COB", "COF", "COP", "CRC", "CSC", "CSK",
        "CUP", "CUX", "CVE", "CWG", "CYP", "CZK", "DDM", "DEM", "DES", "DJF", "DKK",
        "DOP", "DZD", "DZF", "DZG", "ECS", "ECV", "EEK", "EGP", "ERN", "ESP", "ETB",
        "ETD", "EUR", "FIM", "FIN", "FJD", "FJP", "FKP", "FOK", "FRF", "FRG", "GAF",
        "GBP", "GEK", "GEL", "GHC", "GHO", "GHP", "GHR", "GIP", "GLK", "GMD", "GMP",
        "GNF", "GNI", "GNS", "GPF", "GQE", "GQF", "GQP", "GRD", "GRN", "GTQ", "GUF",
        "GWE", "GWM", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IBP",
        "IDG", "IDJ", "IDN", "IDR", "IEP", "ILL", "ILP", "ILS", "IMP", "INR", "IQD",
        "IRR", "ISK", "ITL", "JEP", "JMD", "JMP", "JOD", "JPY", "KES", "KGS", "KHO",
        "KHR", "KID", "KMF", "KPP", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZR",
        "KZT", "LAK", "LBP", "LIF", "LKR", "LNR", "LRD", "LSL", "LTL", "LTT", "LUF",
        "LVL", "LVR", "LYB", "LYD", "LYP", "MAD", "MAF", "MCF", "MCG", "MDC", "MDL",
        "MDR", "MGA", "MGF", "MHD", "MKD", "MKN", "MLF", "MMK", "MMX", "MNT", "MOP",
        "MQF", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MWP", "MXN", "MXP",
        "MXV", "MYR", "MZE", "MZM", "NAD", "NCF", "NGN", "NGP", "NHF", "NIC", "NIG",
        "NIO", "NLG", "NOK", "NPR", "NZD", "NZP", "OMR", "OMS", "PAB", "PDK", "PDN",
        "PDR", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLX", "PLZ", "PSP",
        "PTC", "PTE", "PYG", "QAR", "REF", "ROL", "RON", "RUB", "RUR", "RWF", "SAR",
        "SAS", "SBD", "SCR", "SDD", "SDP", "SEK", "SGD", "SHP", "SIB", "SIT", "SKK",
        "SLL", "SML", "SOS", "SQS", "SRG", "SSP", "STD", "STE", "SUN", "SUR", "SVC",
        "SYP", "SZL", "TCC", "TDF", "THB", "TJR", "TJS", "TMM", "TND", "TOP", "TOS",
        "TPE", "TPP", "TRL", "TTD", "TTO", "TVD", "TWD", "TZS", "UAH", "UAK", "UGS",
        "UGX", "USD", "USN", "USS", "UYF", "UYP", "UYU", "UZC", "UZS", "VAL", "VDD",
        "VDN", "VDP", "VEB", "VGD", "VND", "VNN", "VNR", "VNS", "VUV", "WSP", "WST",
        "XAD", "XAF", "XAM", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XCF", "XDR",
        "XEF", "XEU", "XFO", "XFU", "XID", "XMF", "XNF", "XOF", "XPF", "XPS", "XSS",
        "XTR", "YDD", "YEI", "YER", "YUD", "YUF", "YUG", "YUM", "YUN", "YUO", "YUR",
        "ZAL", "ZAP", "ZAR", "ZMK", "ZMP", "ZRN", "ZRZ", "ZWD"
    };

    UErrorCode status = U_ZERO_ERROR;
    int32_t i = 0, j = 0;
    int32_t noLocales = uloc_countAvailable();
    char locale[256];
    char currLoc[256];
    UChar result[4];
    UChar currBuffer[256];


    for(i = 0; i < noLocales; i++) {
        strcpy(currLoc, uloc_getAvailable(i));
        for(j = 0; j < UPRV_LENGTHOF(currencies); j++) {
            strcpy(locale, currLoc);
            strcat(locale, "@currency=");
            strcat(locale, currencies[j]);
            ucurr_forLocale(locale, result, 4, &status);
            u_charsToUChars(currencies[j], currBuffer, 3);
            currBuffer[3] = 0;
            if(u_strcmp(currBuffer, result) != 0) {
                log_err("Didn't get the right currency for %s\n", locale);
            }
        }

    }
}
Example #10
0
static void print_icu_xml_locales(const struct config_t *p_config)
{
    int32_t count;
    int32_t i;
    UErrorCode status = U_ZERO_ERROR;

    UChar keyword[64];
    int32_t keyword_len = 0;
    char keyword_str[128];
    int32_t keyword_str_len = 0;

    UChar language[64];
    int32_t language_len = 0;
    char lang_str[128];
    int32_t lang_str_len = 0;

    UChar script[64];
    int32_t script_len = 0;
    char script_str[128];
    int32_t script_str_len = 0;

    UChar location[64];
    int32_t location_len = 0;
    char location_str[128];
    int32_t location_str_len = 0;

    UChar variant[64];
    int32_t variant_len = 0;
    char variant_str[128];
    int32_t variant_str_len = 0;

    UChar name[64];
    int32_t name_len = 0;
    char name_str[128];
    int32_t name_str_len = 0;

    UChar localname[64];
    int32_t localname_len = 0;
    char localname_str[128];
    int32_t localname_str_len = 0;

    count = uloc_countAvailable() ;

    if (p_config->xmloutput)
    {
        fprintf(p_config->outfile, "<locales count=\"%d\" default=\"%s\" collations=\"%d\">\n",
                count, uloc_getDefault(), ucol_countAvailable());
    }
    else
    {
        fprintf(p_config->outfile, "Available ICU locales: %d\n", count);
        fprintf(p_config->outfile, "Default locale is: %s\n",  uloc_getDefault());
    }

    for (i = 0; i < count; i++)
    {

        keyword_len
            = uloc_getDisplayKeyword(uloc_getAvailable(i), "en",
                                     keyword, 64,
                                     &status);

        u_strToUTF8(keyword_str, 128, &keyword_str_len,
                    keyword, keyword_len,
                    &status);


        language_len
            = uloc_getDisplayLanguage(uloc_getAvailable(i), "en",
                                      language, 64,
                                      &status);

        u_strToUTF8(lang_str, 128, &lang_str_len,
                    language, language_len,
                    &status);


        script_len
            = uloc_getDisplayScript(uloc_getAvailable(i), "en",
                                    script, 64,
                                    &status);

        u_strToUTF8(script_str, 128, &script_str_len,
                    script, script_len,
                    &status);

        location_len
            = uloc_getDisplayCountry(uloc_getAvailable(i), "en",
                                     location, 64,
                                     &status);

        u_strToUTF8(location_str, 128, &location_str_len,
                    location, location_len,
                    &status);

        variant_len
            = uloc_getDisplayVariant(uloc_getAvailable(i), "en",
                                     variant, 64,
                                     &status);

        u_strToUTF8(variant_str, 128, &variant_str_len,
                    variant, variant_len,
                    &status);

        name_len
            = uloc_getDisplayName(uloc_getAvailable(i), "en",
                                  name, 64,
                                  &status);

        u_strToUTF8(name_str, 128, &name_str_len,
                    name, name_len,
                    &status);

        localname_len
            = uloc_getDisplayName(uloc_getAvailable(i), uloc_getAvailable(i),
                                  localname, 64,
                                  &status);

        u_strToUTF8(localname_str, 128, &localname_str_len,
                    localname, localname_len,
                    &status);


        if (p_config->xmloutput)
        {
            fprintf(p_config->outfile, "<locale id=\"%s\"", uloc_getAvailable(i));
            if (strlen(lang_str))
                fprintf(p_config->outfile, " language=\"%s\"", lang_str);
            if (strlen(script_str))
                fprintf(p_config->outfile, " script=\"%s\"", script_str);
            if (strlen(location_str))
                fprintf(p_config->outfile, " location=\"%s\"", location_str);
            if (strlen(variant_str))
                fprintf(p_config->outfile, " variant=\"%s\"", variant_str);
            if (strlen(name_str))
                fprintf(p_config->outfile, " name=\"%s\"", name_str);
            if (strlen(localname_str))
                fprintf(p_config->outfile, " localname=\"%s\"", localname_str);
            fprintf(p_config->outfile, ">");
            if (strlen(localname_str))
                fprintf(p_config->outfile, "%s", localname_str);
            fprintf(p_config->outfile, "</locale>\n");
        }
        else if (1 == p_config->xmloutput)
        {
            fprintf(p_config->outfile, "%s", uloc_getAvailable(i));
            fprintf(p_config->outfile, " | ");
            if (strlen(name_str))
                fprintf(p_config->outfile, "%s", name_str);
            fprintf(p_config->outfile, " | ");
            if (strlen(localname_str))
                fprintf(p_config->outfile, "%s", localname_str);
            fprintf(p_config->outfile, "\n");
        }
        else
            fprintf(p_config->outfile, "%s\n", uloc_getAvailable(i));
    }
    if (p_config->xmloutput)
        fprintf(p_config->outfile, "</locales>\n");
    else
        fprintf(p_config->outfile, "\n");

    if (U_FAILURE(status))
    {
        fprintf(stderr, "ICU Error: %d %s\n", status, u_errorName(status));
        exit(2);
    }
}