internationalization

i18n

Language Neutral Date and Time Formatting in PHP via the MessageFormatter class

<?php

// Setting parameters
$time   = time();
$values = [7, $time, $time];

// Prints "At 3:50:31 PM on Apr 19, 2015, there was a disturbance on planet 7."
$pattern   = "At {1, time} on {1, date}, there was a disturbance on planet {0, number}.";
$formatter = new MessageFormatter("en_US", $pattern);
echo $formatter->format($values);

// Prints "À 15:53:01 le 19 avr. 2015, il y avait une perturbation sur la planète 7."
$pattern   = "À {1, time} le {1, date}, il y avait une perturbation sur la planète {0, number}.";
$formatter = new MessageFormatter("fr_FR", $pattern);
echo $formatter->format($values);

?>

ICU4J Plurality for Scala via the MessageFormat class

import com.ibm.icu.text.MessageFormat
import java.util.Locale
import scala.collection.JavaConverters._
 

// Outputs "A common message for all options. Selected: (other)"
val formatted = new MessageFormat(
  "{messageCount, plural, one {{aMessage} (one)} other {{aMessage} (other)} }",
  new java.util.Locale("en_US")
).format(Map(
  "messageCount" -> 900,
  "aMessage" -> "A common message for all options. Selected: "
).asJava)

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow