RinkAttendant6 / JsonI18n

Simple PHP internationalization library using JSON data
Mozilla Public License 2.0
4 stars 1 forks source link

Add support for positional placeholders #12

Open RinkAttendant6 opened 8 years ago

RinkAttendant6 commented 8 years ago

It is common to have positional placeholders when localizing due to differences in word order in different languages.

There exists several different formats for positional placeholders. For example:

// ICU format:
'{0, number} files exist on disk {1} at this time'

 // jquery.i18n format:
'$1 files exist on disk $2 at this time'

// PHP printf format
'%1$d files exist on disk %2$s at this time'

Since sprintf and vsprintf are currently being used, the last format already works.

It would be nice to support the jquery.i18n format by parsing the strings and converting the placeholders to printf-style placeholders. However since it does not specify type for its placeholders (string, number, etc.), they would be assumed string by default. A possible improvement would be to look for {{PLURAL to determine if the placeholder could be an integer.