Feature #7724

Implement Message Formatter subsystem

Added by Karol Gusak about 5 years ago. Updated almost 5 years ago.

Status:Resolved Start date:
Priority:Must have Due date:
Assigned To:Karol Gusak % Done:

100%

Category:I18n
Target version:TYPO3 Flow Base Distribution - 1.0 alpha 11
PHP Version: Complexity:
Has patch:

Description

Message Formatter is a class which formats a string given by substituting placeholders with properly formatted values. Placeholders consists of an unsigned integer enclosed in curly braces. Optionally format type can be set, and this one can set even more precisely by format style. Examples:

  • You have {0} items in cart, total value: {1}
  • You have {0,number} items in cart, total value: {1,number}
  • You have {0,number,integer} items in cart, total value: {1,number,currency}

Format types are classes implementing simple API, so developers can create custom format types, and they can have custom format styles.

Number, Date, and Time format types will be implemented by default.

ViewHelpers for Fluid will be implemented in order to make use of Message Formatter subsystem in template files.


Related issues

related to TYPO3.Flow - Feature #6724: Internationalization, locale, multi-language ect. Resolved

Associated revisions

Revision 4f3e0d41
Added by Karol Gusak about 5 years ago

[+FEATURE] FLOW3 (Locale): Added base code for message formatting. Relates to #7724.

Revision f27a0afd
Added by Karol Gusak about 5 years ago

[~TASK][~API] FLOW3 (Locale): Renamed DateTimeFormatter to DatetimeFormatter in order to access it as "datetime" (and not "dateTime") in placeholders. Relates to #7724.

Revision 419cba15
Added by Karol Gusak about 5 years ago

[~TASK] FLOW3 (I18n): Moved formatting functionality from DatesReader to DatetimeFormatter. Relates to #7722, 7724.

Revision b5c6c641
Added by Karol Gusak about 5 years ago

[~TASK] FLOW3 (I18n): Added new test for DatetimeFormatter. Relates to #7724.

Revision 3a28df25
Added by Karol Gusak about 5 years ago

[~TASK] FLOW3 (I18n): Moved formatting functionality from NumbersReader to NumberFormatter. Relates to #7722, #7724.
[~TASK] FLOW3 (I18n): Minor code cleaning.

History

#1 Updated by Karol Gusak about 5 years ago

  • Status changed from New to Accepted

#2 Updated by Karol Gusak about 5 years ago

  • Status changed from Accepted to Needs Feedback
  • % Done changed from 0 to 30
Base implementation of message formatting was commited. This is how it works:
  • FormatResolver is a class which is used to replace all placeholders in string with corresponding formatted values
  • It uses classes implementing FormatterInterface (i.e. formatters) in order to format a value as defined in the placeholder
  • Some formatters use readers (classes named like FooReader from \F3\FLOW3\Locale\Cldr\Reader namespace)
  • Readers won't be accessed directly by application developer. They abstract CLDR and provide methods to operate on this data. For example, NumberFormatter uses NumbersReader to do actual formatting (as only NumbersReader knows the rules/patterns from CLDR)

Please note the naming: NumbersReader because it abstracts "numbers" tag from CLDR, but NumberFormatter because to use it one should write "number" in placeholder.

Some placeholder examples to make it clear:
  • {0}, {1} etc - Places string-casted version of a value (number in brackets defines the value's index from values array provided)
  • {0,number,decimal} or {0,number} - Format as decimal number using pattern from CLDR defined for current locale
  • {0,datetime} - Format as date and time
  • {0,datetime,time,full} - Format only time part, choose the "full" version of pattern from CLDR

Second element in the placeholder defines name of concrete formatter. Remaining elements are passed directly to the formatter (for example, NumberFormatter uses only one additional element, defining if format value as decimal, or percentage, but DatetimeFormatter accepts two elements - style (datetime, date or time) and length (full, long, medium, short).

After writing this I actually think that DatetimeFormatter should be divided into DateFormatter, TimeFormatter, and DatetimeFormatter, which would make defining placeholders more clear (but will be redundant).

And another related topic I would like to ask you about - how should the currency amounts be represented in FLOW3? I think simple Currency object would be nice, it would store a decimal number and a international currency symbol.

What do you think?

#3 Updated by Karol Gusak almost 5 years ago

  • Status changed from Needs Feedback to Resolved
  • % Done changed from 30 to 100

This issue is done, related issue opened #9313.

#4 Updated by Karsten Dambekalns almost 5 years ago

  • Target version set to 1.0 alpha 11

Also available in: Atom PDF