Search in sources :

Example 11 with CLDR

use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.

the class MessageFormatsTest method testInterval.

@Test
public void testInterval() {
    String actual;
    CLDR cldr = CLDR.get("en");
    MessageFormats formats = new MessageFormats(cldr);
    formats.setTimeZone("America/New_York");
    String message = "{0;1 datetime-interval}";
    long epoch = 1582129775000L;
    long extra = 86400000 + 3600000;
    MessageArgs args = args().add(new LongNode(epoch)).add(new LongNode(epoch + extra));
    actual = formats.formatter().format(message, args);
    assertEquals(actual, "Feb 19 – 20, 2020");
}
Also used : MessageArgs(com.squarespace.cldrengine.api.MessageArgs) CLDR(com.squarespace.cldrengine.CLDR) LongNode(com.fasterxml.jackson.databind.node.LongNode) MessageFormats(com.squarespace.template.MessageFormats) Test(org.testng.annotations.Test)

Example 12 with CLDR

use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.

the class MessageFormatsTest method testCurrency.

@Test
public void testCurrency() {
    String actual;
    CLDR cldr = CLDR.get("en");
    MessageFormats formats = new MessageFormats(cldr);
    formats.setTimeZone("America/New_York");
    String message = "{0 currency style:standard}";
    ObjectNode money = money("12345.789", "USD");
    actual = formats.formatter().format(message, args().add(money));
    assertEquals(actual, "$12,345.79");
    money = newmoney("12345.789", "USD");
    actual = formats.formatter().format(message, args().add(money));
    assertEquals(actual, "$12,345.79");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CLDR(com.squarespace.cldrengine.CLDR) MessageFormats(com.squarespace.template.MessageFormats) Test(org.testng.annotations.Test)

Example 13 with CLDR

use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.

the class PluginUtilsTest method testFormatMoneyCLDR.

@Test
public void testFormatMoneyCLDR() {
    CLDR en = CLDR.get("en-US");
    assertEquals(PluginUtils.formatMoney(new Decimal(1), "USD", en), "$1.00");
    assertEquals(PluginUtils.formatMoney(new Decimal(123.45), "USD", en), "$123.45");
    CLDR de = CLDR.get("de");
    assertEquals(PluginUtils.formatMoney(new Decimal(123.45), "USD", de), "123,45 $");
    assertEquals(PluginUtils.formatMoney(new Decimal(123.45), "EUR", de), "123,45 €");
}
Also used : Decimal(com.squarespace.cldrengine.api.Decimal) CLDR(com.squarespace.cldrengine.CLDR) Test(org.testng.annotations.Test)

Aggregations

CLDR (com.squarespace.cldrengine.CLDR)13 Test (org.testng.annotations.Test)7 MessageFormats (com.squarespace.template.MessageFormats)6 Variable (com.squarespace.template.Variable)5 LongNode (com.fasterxml.jackson.databind.node.LongNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 CalendarDate (com.squarespace.cldrengine.api.CalendarDate)3 Decimal (com.squarespace.cldrengine.api.Decimal)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)1 CurrencyFormatOptions (com.squarespace.cldrengine.api.CurrencyFormatOptions)1 CurrencyType (com.squarespace.cldrengine.api.CurrencyType)1 DateFormatOptions (com.squarespace.cldrengine.api.DateFormatOptions)1 DateIntervalFormatOptions (com.squarespace.cldrengine.api.DateIntervalFormatOptions)1 DecimalFormatOptions (com.squarespace.cldrengine.api.DecimalFormatOptions)1 MessageArgs (com.squarespace.cldrengine.api.MessageArgs)1 RelativeTimeFormatOptions (com.squarespace.cldrengine.api.RelativeTimeFormatOptions)1 BigDecimal (java.math.BigDecimal)1