Skip to content

Add Resource data model #204

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

Closed
wants to merge 3 commits into from
Closed

Conversation

eemeli
Copy link
Collaborator

@eemeli eemeli commented Oct 11, 2021

This PR adds the data model for message resources and groups, i.e. groupings and hierarchical structures of messages. It refers to the Message data type, which is defined in #195.

As requested by @mihnita in the message data model PR, the interfaces' abstract data types are defined separately from their canonical JSON representations, and the metadata is left out. It is my belief that later work with the specification will indicate that it's simpler to merge these definitions, without creating a cost for implementations that choose to use a different internal representation than the canonical JSON.

I am aware of PR #203, and would be happy to work on a design document for this as well as other PRs, once it's defined what that ought to look like and if such a document is desired for this PR.

In my own code, these interfaces are defined here. The generic type parameter is used by the PatternMessage and SelectMessage interfaces to narrow down the pattern element types appropriately. In actual formatting use, these types are used by ResourceReader, which provides a more limited interface; this allows for e.g. non-enumerable message resources to be accessed. The ResourceReader API is in turn used by the getMessage() method of MessageFormat.

In addition to formatting, Resource is also used by @messageformat/compiler when converting MF1 and Fluent messages to MF2, and by @messageformat/xliff during conversion to and from XLIFF 2.

@eemeli
Copy link
Collaborator Author

eemeli commented Oct 11, 2021

Updated to match corresponding changes made to PR #195.

@eemeli eemeli requested a review from stasm October 11, 2021 18:15
Copy link
Contributor

@dminor dminor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good start to me.


A Resource is often the data model representation of a single file,
but may be constructed from any source.
It is not necessary for an implementation to use Resources to hold messages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that Resources are an optional concept and not required to be implemented?
Or that conceptually, you can put all of your messages in a single Resource and avoid the use of multiple resources?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be clarified a bit. My intent here was to communicate that it's entirely possible and allowed for a spec-compliant formatter to not have a need for Resources as an intermediate data structure, if it has other means of providing any message-getting functions.

On the other hand, formatters are by no means the only tools that need to work with messages and message resources; for example XLIFF import/export almost certainly will need a Resource to correspond to its <file> element.

interface Resource {
id: string
locale: string
entries: Record<string, Message | MessageGroup>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since entries here has the same definition as MessageGroup, maybe it would be clear to say that the entries are a MessageGroup?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entries: Record<string, Message | MessageGroup>
group: MessageGroup

Is this what you had in mind? I'm not sure that this additional indirection really helps much. As is, it's possible to think of Resource as an extension of MessageGroup.

@eemeli
Copy link
Collaborator Author

eemeli commented Oct 24, 2022

Closing as out of date after #307

@eemeli eemeli closed this Oct 24, 2022
@eemeli eemeli deleted the add-res-model branch January 23, 2024 08:16
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

Successfully merging this pull request may close these issues.

2 participants