Skip to content

DATETIME and NUMBER functions #2

@tobyzerner

Description

@tobyzerner

Hey @jrmajor, thanks again for your amazing work on this library.

Almost 2 years ago I began my own fluent-php implementation, which was basically a 1:1 port of the JS implementation. It was untested and I never published it or used it in production, so I'm glad you started work on this one which appears to have a much improved architecture and more intent to maintain than I ever had.

However, my implementation did have some additional functionality – specifically, I had implementations of the NUMBER and DATETIME builtin functions. I wanted to share the source code with you now in hope that it can be of use to you.

https://github.com/tobyzerner/fluent-php

Note that the function implementations have a number of caveats, documented in the README:

  • PHP includes the NumberFormatter and IntlDateFormatter classes, but these lack some of the functionality of Intl.NumberFormat and Intl.DateTimeFormat, and thus the full API for the built-in functions cannot be supported. Specifically:
    • In NUMBER, the currencyDisplay option is not supported.
    • In DATETIME, no options are supported except for timeZone. However, the experimental dateStyle and timeStyle options are supported.

But still, I think they're better than nothing. Fluent isn't nearly as useful without them.

On the side, it also had an implementation of DOM Overlays from fluent-dom (also in the form of a 1:1 port), which may also be useful:

Overlay::translateHtml(
    '<p><img data-l10n-name="world" src="world.png"></p>',
    [
        'value' => 'Hello, <img data-l10n-name="world" alt="world">!', 
        'attributes' => ['title' => 'Hello']
    ]
);
// → <p title="Hello">Hello, <img data-l10n-name="world" alt="world" src="world.png">!</p>

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions