Search in sources :

Example 1 with ULocale

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");
}
Also used : RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) ULocale(com.ibm.icu.util.ULocale) Index(org.elasticsearch.index.Index) AnalysisICUPlugin(org.elasticsearch.plugin.analysis.icu.AnalysisICUPlugin) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with ULocale

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();
}
Also used : RuleBasedCollator(com.ibm.icu.text.RuleBasedCollator) ULocale(com.ibm.icu.util.ULocale) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with ULocale

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);
}
Also used : ULocale(com.ibm.icu.util.ULocale) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with ULocale

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.");
    }
}
Also used : ULocale(com.ibm.icu.util.ULocale)

Example 5 with ULocale

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();
}
Also used : ULocale(com.ibm.icu.util.ULocale) Locale(java.util.Locale) ULocale(com.ibm.icu.util.ULocale) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) CacheLoader(com.google.common.cache.CacheLoader) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PostConstruct(javax.annotation.PostConstruct)

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