Skip to content

Additional variable types / Temproal support #634

Closed

Description

@rkh

Currently, fluent-bundle cannot handle Temporal.

What would need to change

It is hardcoded only to support FluentVariable entries (FluentType, string, number, or Date).

Here's how they are resolved:

// Return early if the argument already is an instance of FluentType.
if (arg instanceof FluentType) {
return arg;
}
// Convert the argument to a Fluent type.
switch (typeof arg) {
case "string":
return arg;
case "number":
return new FluentNumber(arg);
case "object":
if (arg instanceof Date) {
return new FluentDateTime(arg.getTime());
}
// eslint-disable-next-line no-fallthrough
default:
scope.reportError(
new TypeError(`Variable type not supported: $${name}, ${typeof arg}`)
);
return new FluentNone(`$${name}`);
}
}

It is, therefore, not possible to pass in other values.

Possible fixes

  • Built-in support for Temporal objects
  • A way to pass in a function to convert custom objects into FluentType instances
  • All of the above

The first one would be very convenient but would also require checking whether Temporal exists.

Project status

As a side note, I'm seeing a lot of old issues with no progress. I'm happy to work on a PR for this, but I'm wondering what the maintenance status of the project is.

Activity

  1. rkh commented on Feb 12, 2025

    @rkh
    ContributorAuthor

    Example of what the API could look like:

    new FluentBundle(locales, {
      wrapVariable(value: Temporal.ZonedDateTime | FluentVariable): FluentVariable {
        if(value instanceof Temporal.ZonedDateTime) {
          return new FluentDateTime(value.epochMilliseconds, { timeZone: value.timeZoneId })
        } else {
          return value
        }
      }
    })
  2. eemeli commented on Feb 12, 2025

    @eemeli
    Member

    The library's still maintained, but new feature development is indeed not very active. I'd be very interested in reviewing new PRs, including ones bringing in Temporal support.

  3. rkh commented on Feb 13, 2025

    @rkh
    ContributorAuthor

    Pull Request: #635

  4. rkh commented on Feb 15, 2025

    @rkh
    ContributorAuthor

    Alternative implementation (more complete Temporal support, but no API for custom values): #636 – happy to integrate this into #635 if that's the preferred approach.

  5. rkh commented on Mar 24, 2025

    @rkh
    ContributorAuthor

    @eemeli I assume this can be closed now?

  6. eemeli commented on Mar 24, 2025

    @eemeli
    Member

    Completed in #636. Release due shortly, once I get some of the dev dependencies refreshed.

  7. Demivan commented on Nov 16, 2025

    @Demivan
    Contributor

    @eemeli This breaks type safety of FluentVariable. I have created a PR to fix it #649

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions