org.appng.api.support

## Class I18n

- java.lang.Object
- - org.appng.api.support.I18n

-     public class I18n
      extends Object

  Utility class used for formatting `String`s, `Date`s and `Number`s. Additionally, a message can be retrieved by delegating to `RequestSupport.getMessage(String, Object...)`.
  Since an instance of `I18n` is being added to each `ExpressionEvaluator` returned by `Request.getExpressionEvaluator()`, you can easily use the methods provided by `I18n` in your expressions.

  ### Examples

  Consider a `ResourceBundle` containing the following entries:

       dateFormat = yyyy-MM-dd
       today = Today: {0}

  Reading the format for a `FieldDef` using `message(String, Object...)`:

       <field name="validFrom" type="date" format="${i18n.message('dateFormat')}">

  leads to

       <field name="validFrom" type="date" format="yyyy-MM-dd">

  Setting the value for a `Label` using `message(String, Object...)` and `formatDate(Date, String)`

       <label>${i18n.message('today', i18n.formatDate(current.date, i18n.message('dateFormat')))}</label>

  leads to (assuming current.today returns a `Date`):

       <label>Today: 2013-03-08</label>

  Author:
    Matthias Müller

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `I18n(Request request)` Creates a new `I18n` which uses the messages and the `Locale` provided by the given `Request`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `format(String format, Object... args)` Formats the given `String` with the given arguments.
    `String` | `formatDate(Date date, String format)` Formats the given `Date` using the given `format`.
    `String` | `formatNumber(Number number, String format)` Formats the given `Number` using the given `format`.
    `String` | `message(String key)` Returns an internationalized message by delegating to `RequestSupport.getMessage(String, Object...)`.
    `String` | `message(String key, Object... args)` Returns an internationalized message by delegating to `RequestSupport.getMessage(String, Object...)`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### I18n

          public I18n(Request request)

      Creates a new `I18n` which uses the messages and the `Locale` provided by the given `Request`.
      Parameters:
        `request` - a `Request`

  - ### Method Detail

    - #### message

          public String message(String key)

      Returns an internationalized message by delegating to `RequestSupport.getMessage(String, Object...)`. Applies the `Locale` provided by `Request.getLocale()`.
      Parameters:
        `key` - the message key
      Returns:
        the message
      See Also:
        `RequestSupport.getMessage(String, Object...)`

    - #### message

          public String message(String key,
                                Object... args)

      Returns an internationalized message by delegating to `RequestSupport.getMessage(String, Object...)`. Applies the `Locale` provided by `Request.getLocale()`.
      Parameters:
        `key` - the message key
        `args` - the message arguments
      Returns:
        the message
      See Also:
        `RequestSupport.getMessage(String, Object...)`

    - #### format

          public String format(String format,
                               Object... args)

      Formats the given `String` with the given arguments. Delegates to `String.format(java.util.Locale, String, Object...)` using the `Locale` provided by `Request.getLocale()`.
      Parameters:
        `format` - the `String` to format
        `args` - the arguments passed to
      Returns:
        a formatted String
      See Also:
        `String.format(Locale, String, Object...)`

    - #### formatDate

          public String formatDate(Date date,
                                   String format)

      Formats the given `Date` using the given `format`. Internally, a `SimpleDateFormat` is being used. Applies the `Locale` provided by `Request.getLocale()`.
      Parameters:
        `date` - the `Date` to format
        `format` - the the format
      Returns:
        the formatted `Number`
      See Also:
        `SimpleDateFormat(String, Locale)`, `DateFormat.format(Date)`

    - #### formatNumber

          public String formatNumber(Number number,
                                     String format)

      Formats the given `Number` using the given `format`. Internally, a `NumberFormat` is being used, which applies the `Locale` provided by `Request.getLocale()`.
      Parameters:
        `number` - the `Number` to format
        `format` - the the format
      Returns:
        the formatted `Number`
      See Also:
        `NumberFormat.getNumberInstance(Locale)`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.