use of com.ibm.icu.util.ULocale in project elasticsearch by elastic.
the class SimpleIcuCollationTokenFilterTests method testCustomRules.
/*
* For german, you might want oe to sort and match with o umlaut.
* This is not the default, but you can make a customized ruleset to do this.
*
* The default is DIN 5007-1, this shows how to tailor a collator to get DIN 5007-2 behavior.
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4423383
*/
public void testCustomRules() throws Exception {
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();
Settings settings = Settings.builder().put("index.analysis.filter.myCollator.type", "icu_collation").put("index.analysis.filter.myCollator.rules", tailoredRules).put("index.analysis.filter.myCollator.strength", "primary").build();
TestAnalysis analysis = createTestAnalysis(new Index("test", "_na_"), settings, new AnalysisICUPlugin());
TokenFilterFactory filterFactory = analysis.tokenFilter.get("myCollator");
assertCollatesToSame(filterFactory, "Töne", "Toene");
}
use of com.ibm.icu.util.ULocale in project lucene-solr by apache.
the class TestICUCollationFieldDocValues 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 {
File tmpFile = createTempDir().toFile();
// 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-dv.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();
FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
IOUtils.write(tailoredRules, os, "UTF-8");
os.close();
return tmpFile.getAbsolutePath();
}
use of com.ibm.icu.util.ULocale in project eclipse.platform.text by eclipse.
the class GlobalTemplateVariablesDateTest method testInvalidLocale.
@Test
public void testInvalidLocale() throws Exception {
TemplateBuffer buffer = fTranslator.translate("Today is ${d:date('YYYY-MM-dd', 'this_invalid_locale')}!");
fType.resolve(buffer, fContext);
StringBuffer expected = new StringBuffer();
expected.append("Today is ");
expected.append(new SimpleDateFormat("YYYY-MM-dd", new ULocale("this_invalid_locale")).format(new java.util.Date()));
expected.append("!");
assertBufferStringAndVariables(expected.toString(), buffer);
}
use of com.ibm.icu.util.ULocale in project validator by validator.
the class LanguageDetectingChecker method checkContentLanguageHeaderNorwegian.
private void checkContentLanguageHeaderNorwegian(String detectedLanguage, String detectedLanguageName, String detectedLanguageCode) throws SAXException {
if ("".equals(httpContentLangHeader) || httpContentLangHeader.contains(",")) {
return;
}
String lowerCaseContentLang = httpContentLangHeader.toLowerCase();
String contentLangCode = new ULocale(lowerCaseContentLang).getLanguage();
if (!("no".equals(contentLangCode) || "nn".equals(contentLangCode) || "nb".equals(contentLangCode))) {
warn("This document appears to be written in" + " Norwegian but the value of the HTTP" + " \u201CContent-Language\u201D header is" + " \u201C" + lowerCaseContentLang + "\u201D. Consider" + " changing it to \u201Cnn\u201D or \u201Cnn\u201D" + " (or variant) instead.");
}
}
use of com.ibm.icu.util.ULocale in project fess by codelibs.
the class SystemHelper method init.
@PostConstruct
public void init() {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
// EOL Date
cal.set(2023, 8 - 1, 8);
eolTime = cal.getTimeInMillis();
if (isEoled()) {
logger.error("Your system is out of support. See https://fess.codelibs.org/eol.html");
}
updateSystemProperties();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
filterPathEncoding = fessConfig.getPathEncoding();
supportedLanguages = fessConfig.getSupportedLanguagesAsArray();
langItemsCache = CacheBuilder.newBuilder().maximumSize(20).expireAfterAccess(1, TimeUnit.HOURS).build(new CacheLoader<String, List<Map<String, String>>>() {
@Override
public List<Map<String, String>> load(final String key) throws Exception {
final ULocale uLocale = new ULocale(key);
final Locale displayLocale = uLocale.toLocale();
final List<Map<String, String>> langItems = new ArrayList<>(supportedLanguages.length);
final String msg = ComponentUtil.getMessageManager().getMessage(displayLocale, "labels.allLanguages");
final Map<String, String> defaultMap = new HashMap<>(2);
defaultMap.put(Constants.ITEM_LABEL, msg);
defaultMap.put(Constants.ITEM_VALUE, "all");
langItems.add(defaultMap);
for (final String lang : supportedLanguages) {
final Locale locale = LocaleUtils.toLocale(lang);
final String label = locale.getDisplayName(displayLocale);
final Map<String, String> map = new HashMap<>(2);
map.put(Constants.ITEM_LABEL, label);
map.put(Constants.ITEM_VALUE, lang);
langItems.add(map);
}
return langItems;
}
});
ComponentUtil.doInitProcesses(Runnable::run);
parseProjectProperties();
}
Aggregations