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);
}
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);
}
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;
}
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;
}
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));
}
Aggregations