Skip to content

Different variable values #917

@rkh

Description

@rkh

Clear and concise description of the problem

It would be nice if there was a way to support more variable types than numbers, strings, and Date instances.

Things that come to mind are Temporal objects or Vue references.

Suggested solution

Support passing in a configuration option to map variable values to FluentType instance. This could be done as a function, or an object mapping, or something else.

Example:

const fluent = createFluentVue({
  wrapVariable(value: Temporal.ZonedDateTime | FluentVariable): FluentVariable {
    if(value instanceof Temporal.ZonedDateTime) {
      return new FluentDateTime(value.epochMilliseconds, { timeZone: value.timeZoneId })
    } else {
      return value
    }
  }
})

Alternative

A few alternatives:

  1. Implement this functionality in fluent-bundle itself, then support the API addition here. My main concern would be getting it implemented, merged, released, and then integrated here in any reasonable timeframe. This could be combined with other solutions, though – first implement something with the current fluent-bundle, then move to using the new API once it has been released. See Additional variable types / Temproal support projectfluent/fluent.js#634
  2. Wrapping the FluentBundle instances passed to createFluentVue – this was my first idea, but didn't work because inheritBundle would drop any wrapper.
  3. Override properties and directives defined by createFluentVue.
  4. No support. Will have to manually wrap Temporal instances and other objects before any call to $t or similar.

Additional context

Happy to work on a pull request.

Validations

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy