Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional variable types / Temproal support #634

Open
rkh opened this issue Feb 12, 2025 · 4 comments
Open

Additional variable types / Temproal support #634

rkh opened this issue Feb 12, 2025 · 4 comments

Comments

@rkh
Copy link

rkh commented Feb 12, 2025

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.

@rkh
Copy link
Author

rkh commented Feb 12, 2025

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
    }
  }
})

@eemeli
Copy link
Member

eemeli commented Feb 12, 2025

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.

@rkh
Copy link
Author

rkh commented Feb 13, 2025

Pull Request: #635

@rkh
Copy link
Author

rkh commented Feb 15, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants