Search in sources :

Example 6 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class PluralRulesObject method createPluralRules.

private PluralRules createPluralRules() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    PluralType pluralType = "cardinal".equals(type) ? PluralType.CARDINAL : PluralType.ORDINAL;
    return PluralRules.forLocale(locale, pluralType);
}
Also used : ULocale(com.ibm.icu.util.ULocale) PluralType(com.ibm.icu.text.PluralRules.PluralType)

Example 7 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class IntlAbstractOperations method createLocaleEntry.

private static LocaleEntry createLocaleEntry(LocaleMatcher matcher, String locale) {
    ULocale canonicalized = matcher.canonicalize(ULocale.forLanguageTag(locale));
    ULocale maximized = addLikelySubtagsWithDefaults(canonicalized);
    return new LocaleEntry(canonicalized, maximized);
}
Also used : ULocale(com.ibm.icu.util.ULocale)

Example 8 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class IntlAbstractOperations method isBetterMatch.

/**
 * Requests for "en-US" give two results with a perfect score:
 * <ul>
 * <li>[en; en, en_Latn_US]
 * <li>[en-US; en_US, en_Latn_US]
 * </ul>
 * Prefer the more detailed result value, i.e. "en-US".
 *
 * @param requested
 *            the requested locale
 * @param oldMatch
 *            the previous match
 * @param newMatch
 *            the new match
 * @return {@code true} if the new match is better than the previous one
 */
private static boolean isBetterMatch(LocaleEntry requested, LocaleEntry oldMatch, LocaleEntry newMatch) {
    ULocale canonicalized = requested.getCanonicalized();
    ULocale oldCanonicalized = oldMatch.getCanonicalized();
    ULocale newCanonicalized = newMatch.getCanonicalized();
    // Compare language.
    String language = canonicalized.getLanguage();
    String newLanguage = newCanonicalized.getLanguage();
    String oldLanguage = oldCanonicalized.getLanguage();
    assert !newLanguage.isEmpty() && !oldLanguage.isEmpty();
    if (newLanguage.equals(language) && !oldLanguage.equals(language)) {
        return true;
    }
    // Compare script.
    String script = canonicalized.getScript();
    String newScript = newCanonicalized.getScript();
    String oldScript = oldCanonicalized.getScript();
    if ((newScript.equals(script) && !oldScript.equals(script)) || (newScript.isEmpty() && !oldScript.isEmpty() && !oldScript.equals(script))) {
        return true;
    }
    // Compare region.
    String region = canonicalized.getCountry();
    String newRegion = newCanonicalized.getCountry();
    String oldRegion = oldCanonicalized.getCountry();
    if ((newRegion.equals(script) && !oldRegion.equals(region)) || (newRegion.isEmpty() && !oldRegion.isEmpty() && !oldRegion.equals(region))) {
        return true;
    }
    return false;
}
Also used : ULocale(com.ibm.icu.util.ULocale)

Example 9 with ULocale

use of com.ibm.icu.util.ULocale in project lucene-solr by apache.

the class TestICUCollationField method setupSolrHome.

/**
   * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
   * These are largish files, and jvm-specific (as our documentation says, you should always
   * look out for jvm differences with collation).
   * So it's preferable to create this file on-the-fly.
   */
public static String setupSolrHome() throws Exception {
    String tmpFile = createTempDir().toFile().getAbsolutePath();
    // make data and conf dirs
    new File(tmpFile + "/collection1", "data").mkdirs();
    File confDir = new File(tmpFile + "/collection1", "conf");
    confDir.mkdirs();
    // copy over configuration files
    FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"), new File(confDir, "solrconfig.xml"));
    FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/schema-icucollate.xml"), new File(confDir, "schema.xml"));
    // generate custom collation rules (DIN 5007-2), saving to customrules.dat
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de", "DE"));
    String DIN5007_2_tailorings = "& ae , ä & AE , Ä" + "& oe , ö & OE , Ö" + "& ue , ü & UE , ü";
    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();
    final String osFileName = "customrules.dat";
    final FileOutputStream os = new FileOutputStream(new File(confDir, osFileName));
    IOUtils.write(tailoredRules, os, "UTF-8");
    os.close();
    final ResourceLoader loader;
    if (random().nextBoolean()) {
        loader = new StringMockResourceLoader(tailoredRules);
    } else {
        loader = new FilesystemResourceLoader(confDir.toPath());
    }
    final Collator readCollator = ICUCollationField.createFromRules(osFileName, loader);
    assertEquals(tailoredCollator, readCollator);
    return tmpFile;
}
Also used : ResourceLoader(org.apache.lucene.analysis.util.ResourceLoader) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader) FilesystemResourceLoader(org.apache.lucene.analysis.util.FilesystemResourceLoader) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) FilesystemResourceLoader(org.apache.lucene.analysis.util.FilesystemResourceLoader) ULocale(com.ibm.icu.util.ULocale) FileOutputStream(java.io.FileOutputStream) File(java.io.File) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader) RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) Collator(com.ibm.icu.text.Collator)

Example 10 with ULocale

use of com.ibm.icu.util.ULocale in project closure-templates by google.

the class FormatNumDirective method applyForJava.

@Override
public SoyValue applyForJava(SoyValue value, List<SoyValue> args) {
    ULocale uLocale = I18nUtils.parseULocale(localeStringProvider.get());
    String formatType = args.isEmpty() ? DEFAULT_FORMAT : args.get(0).stringValue();
    String numbersKeyword = "local";
    if (args.size() > 1) {
        // A keyword for ULocale was passed (like 'native', for instance, to use native characters).
        numbersKeyword = args.get(1).stringValue();
    }
    // Minimum and maximum fraction digits. If only one value was specified, use as both min and max
    // (i.e. significant digits after the decimal point).
    Integer minFractionDigits = args.size() > 2 ? Integer.valueOf((int) args.get(2).numberValue()) : null;
    Integer maxFractionDigits = args.size() > 3 ? Integer.valueOf((int) args.get(3).numberValue()) : minFractionDigits;
    double number = value.numberValue();
    return StringData.forValue(I18NDirectivesRuntime.formatNum(uLocale, number, formatType, numbersKeyword, minFractionDigits, maxFractionDigits));
}
Also used : ULocale(com.ibm.icu.util.ULocale) LocaleString(com.google.template.soy.shared.restricted.ApiCallScopeBindingAnnotations.LocaleString)

Aggregations

ULocale (com.ibm.icu.util.ULocale)25 RuleBasedCollator (com.ibm.icu.text.RuleBasedCollator)5 Collator (com.ibm.icu.text.Collator)2 DateTimePatternGenerator (com.ibm.icu.text.DateTimePatternGenerator)2 DecimalFormat (com.ibm.icu.text.DecimalFormat)2 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Detector (com.cybozu.labs.langdetect.Detector)1 LangDetectException (com.cybozu.labs.langdetect.LangDetectException)1 Language (com.cybozu.labs.langdetect.Language)1 Skeleton (com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.Skeleton)1 CacheLoader (com.google.common.cache.CacheLoader)1 LocaleString (com.google.template.soy.shared.restricted.ApiCallScopeBindingAnnotations.LocaleString)1 ICUResourceBundle (com.ibm.icu.impl.ICUResourceBundle)1 BreakIterator (com.ibm.icu.text.BreakIterator)1 ListFormatter (com.ibm.icu.text.ListFormatter)1