Search in sources :

Example 1 with MeasurementSystem

use of com.squarespace.cldr.units.MeasurementSystem in project template-compiler by Squarespace.

the class UnitsMetricPredicate method apply.

@Override
public boolean apply(Context ctx, Arguments arguments) throws CodeExecuteException {
    CLDR.Locale locale = ctx.cldrLocale();
    if (locale == null) {
        return true;
    }
    String category = (String) arguments.getOpaque();
    if (category == null) {
        return true;
    }
    UnitConverter converter = CLDR_INSTANCE.getUnitConverter(locale);
    MeasurementSystem system = converter.measurementSystem();
    switch(category) {
        case "consumption":
        case "length":
        case "liquid":
        case "mass":
        case "speed":
        case "volume":
            return system == METRIC || system == METRIC_WITH_US_TEMPERATURE;
        case "temperature":
            return system == METRIC || system == US_WITH_METRIC_TEMPERATURE;
        default:
            break;
    }
    return true;
}
Also used : MeasurementSystem(com.squarespace.cldr.units.MeasurementSystem) CLDR(com.squarespace.cldr.CLDR) UnitConverter(com.squarespace.cldr.units.UnitConverter)

Aggregations

CLDR (com.squarespace.cldr.CLDR)1 MeasurementSystem (com.squarespace.cldr.units.MeasurementSystem)1 UnitConverter (com.squarespace.cldr.units.UnitConverter)1