Skip to content

Proposal: add unit system metadata - #148

Open
LukaHummel wants to merge 1 commit into
cooklang:mainfrom
LukaHummel:agent/add-unit-system-metadata-proposal
Open

LukaHummel wants to merge 1 commit into
cooklang:mainfrom
LukaHummel:agent/add-unit-system-metadata-proposal

Conversation

@LukaHummel

@LukaHummel LukaHummel commented Aug 2, 2026 •

Copy link
Copy Markdown

Summary

  • propose an optional recipe-level unit system metadata key
  • standardize metric, imperial, and us customary source-system values
  • define client behavior for ambiguous units, mixed-system recipes, unsupported conversions, and best-fit formatting

Motivation

Cooklang supports serving-based scaling, but clients do not have a portable source-system hint for unit conversion. This proposal lets recipe authors distinguish systems such as British Imperial and US customary while leaving conversion tables, rounding, target units, and presentation policy to each client.

This addresses #142.

Impact

The proposal does not change Cooklang grammar or require clients to implement conversion. Existing parsers can expose the key through generic YAML metadata, and clients without conversion support continue rendering recipes unchanged.

Full Proposal

@LukaHummel
LukaHummel marked this pull request as ready for review August 2, 2026 12:39
@dubadub

dubadub commented Sep 12, 2026

Copy link
Copy Markdown
Member

Hey, sorry, just noticed your proposal, will have a look next few days.

@tmlmt

tmlmt commented Nov 5, 2026

Copy link
Copy Markdown

I think the proposal touches upon a real problem for consumer applications related to ambiguous units. However:

  1. The limitation to three possible values is rather US/European-centric and does not include other regional culinary conventions. Example, the Japanese rice-cooker "cup" is 180mL and different from the metric or US cup.

  2. I'm not entirely convinced by the distinction between us customary and imperial. US customary and British Imperial are closely related systems that share many units (e.g. pounds, ounces, inches), but differ in certain definitions, particularly volume measurements. If the intention is to distinguish regional variants, wouldn't us and uk be more intuitive and consistent?

I could suggest to simply suggest defining the unit system metadata key as a convention

@LukaHummel

Copy link
Copy Markdown
Author

@tmlmt

  1. I fully agree. I only would limit initial definitions to keep the scope of this proposal sensible, but I would definitely open the standardized units to more values. The clients can decide which values they accept in the field.
  2. I think imperial should stay distinct from uk. There might be multiple regions that use imperial in cooking that can use this value. On the other hand it probably is easier to use us instead of us customary.
    In the end I would expect cooklang only to give guidance to the clients and let them decide how to parse the values.

@tmlmt

tmlmt commented Nov 6, 2026

Copy link
Copy Markdown

@tmlmt

  1. I fully agree. I only would limit initial definitions to keep the scope of this proposal sensible, but I would definitely open the standardized units to more values. The clients can decide which values they accept in the field.

  2. I think imperial should stay distinct from uk. There might be multiple regions that use imperial in cooking that can use this value. On the other hand it probably is easier to use us instead of us customary.

In the end I would expect cooklang only to give guidance to the clients and let them decide how to parse the values.

Agreed

@Plommonsorbet

Copy link
Copy Markdown

Up front: this overlaps heavily with the locale and unit work I mentioned on Discord, and I have not settled how to present that, likely a proposal of its own in the coming week. So read this as comments on yours rather than a counter-proposal.

Density is out of scope here. It deserves a proposal of its own, so I am not commenting on it in this thread or in #166. It has nothing to do with unit systems or unit parsing, it needs ingredient data where the rest needs definitions, and it is a new capability rather than a fix to an existing one.

Numbered so they are easy to reply to.

Worth flagging

  1. Proposal 0021: alternative units and dual quantities #157 endorses this proposal and Proposal 0028: units on the shopping list and in recipe references #166 contradicts it. This one leaves conversion ratios and regional definitions to clients, and Proposal 0021: alternative units and dual quantities #157 agrees: "Those stay client-owned, as PR Proposal: add unit system metadata #148 proposes." Proposal 0028: units on the shopping list and in recipe references #166 needs the opposite, and names this proposal:

    A unit table in the conventions. PR Proposal: add unit system metadata #148 leaves conversion tables to each application. This proposal needs tools to agree on which names are the same unit and on the ratios, or two tools give different totals from the same files.

    Both of those are dubadub's. Flagging it because a unit table in the conventions and client-owned conversion cannot both be the rule, and it is hard to see from inside any one proposal.

Agreements

  1. A recipe should be able to say how its own units are read. What this is asking for is a key, and I agree with that. What the key should carry is my point 7.

  2. The declaration settles ambiguous names only. cup and pint need it, gram and ounce do not, and "2%oz in a recipe marked unit system: metric still means ounces" is the right rule: the key never reinterprets a unit that was already unambiguous.

  3. Conversion is the client's, and a quantity it cannot convert is shown as written.

  4. Rounding, fractions, significant digits, preferred output and display are the client's concern.

Suggestions

  1. Identity and exact ratios cannot be left to the client if the goal is interoperability. An imperial pint is 568.26125 ml and a US pint is 473.176473 ml. The key says which of the two a recipe means, but not what either one is, so each client supplies its own figure and two conformant clients can still read one declared recipe differently. I have most of that built already: a closed set of 52 units, each with an exact factor and a citation for where the number comes from. If the language owns identity and ratios, the table is not the hard part.

  2. The key should carry a locale tag. tmlmt's two objections point the same way. Three values cannot reach his 180 ml rice-cooker cup, and on us against uk: the 1959 yard and pound agreement unified the pound and the yard, but volume was never unified, so what the two systems dispute is a handful of volume definitions. That is a regional difference, so regions are the right labels, and BCP 47 carries them along with the language, which is what my work keys on. Opening the value list up arrives at the same place one region at a time. So I am for a way to say the unit system, as long as it is the same key that names the language and the region rather than a second one beside it.

  3. A spec entry is a contract, and nothing implements this yet. Anyone can already put any key in their own recipes and have their own tool act on it, and that needs no proposal. What the conventions add is an obligation on everyone else, and unlike an extension it cannot be withdrawn by one project. CONTRIBUTING already orders it that way, "it will be added to main specification as soon as official applications ... implement required features", so what I am asking is only that the test comes before acceptance fixes the design rather than after. Without an implementation it is also hypothetical, and the YAML spec is the example I would not want to repeat: it outran its parsers, so it has corners almost nothing implements, and an unquoted no is still a boolean in one library and a string in another. Nothing can act on this key today: in cooklang-rs a parser holds a single converter, CooklangParser::new(extensions, converter), and GroupedQuantity::add takes one, so a client can bring its own unit table but only one at a time. A shopping list adds two recipes' amounts through a single converter, which is exactly where a mixed collection needs two. Specifying first also fixes the scope before anyone knows whether it is possible, or reasonable to implement. I would rather the reading side worked in a parser first and the spec followed it. That is the test I am holding my own locale work to, and that work implements exactly this part.

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.

4 participants