All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squarespace.cldr.CLDRBase Maven / Gradle / Ivy

package com.squarespace.cldr;

import java.util.HashMap;
import java.util.Map;

import com.squarespace.cldr.dates.CalendarFormatter;
import com.squarespace.cldr.numbers.NumberFormatter;


/**
 * Common Localization Data Repository (CLDR) base class.
 */
public abstract class CLDRBase {

  // TODO: method to resolve appropriate cldr locale from java locale
  // TODO: locale matching logic
  
  protected static final Map defaultContent = new HashMap<>();
  protected static final LazyLoader calendarFormatters = new LazyLoader<>();
  protected static final LazyLoader numberFormatters = new LazyLoader<>();
  
  public CLDRLocale getLocale(CLDRLocale locale) {
    return defaultContent.getOrDefault(locale, locale);
  } 
  
  public CalendarFormatter getCalendarFormatter(CLDRLocale locale) {
    return calendarFormatters.get(getLocale(locale));
  }

  public NumberFormatter getNumberFormatter(CLDRLocale locale) {
    return numberFormatters.get(getLocale(locale));
  }
  
  protected static void registerCalendarFormatter(CLDRLocale locale, Class cls) {
    calendarFormatters.put(locale, cls);
  }
  
  protected static void registerNumberFormatter(CLDRLocale locale, Class cls) {
    numberFormatters.put(locale, cls);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy