Documentation
¶
Overview ¶
Package foodsafety is the Menuella food-safety vocabulary: EU Reg. 1169/2011 Annex II allergens and the Menuella declarations, in six languages.
Semantic keys instead of country-specific numbers — store the key, render the code, never the reverse.
de, err := foodsafety.GetDisclosures("de")
// allergen "WHEAT" → "Enthält Getreide und glutenhaltige Erzeugnisse"
This package does not do i18n. Hand it the locale your application already resolved; it will not sniff the environment, negotiate, or quietly fall back.
The dataset is embedded at compile time, so the binary is self-contained and there is nothing to find on disk at runtime. encoding/json is in the standard library, so the module has no dependencies.
Index ¶
- Constants
- Variables
- func AllergenKeys() ([]string, error)
- func CodeScheme() (string, error)
- func DeclarationKeys() ([]string, error)
- func IconNames() ([]string, error)
- func IconToSVG(name string, opts SVGOptions) (string, error)
- func IsAllergenKey(value string) bool
- func IsDeclarationKey(value string) bool
- func IsLocale(value string) bool
- func LoadDataset(name string) ([]byte, error)
- func Locales() []string
- type Allergen
- type Codes
- type Declaration
- type Disclosures
- type Icon
- type IconNode
- type SVGOptions
Constants ¶
const FallbackLocale = "en"
FallbackLocale is the locale a bundle falls back to for anything it does not itself carry.
Variables ¶
var ( // ErrUnsupportedLocale means the locale has no bundle. Locales lists those // that do. ErrUnsupportedLocale = errors.New("foodsafety: unsupported locale") // ErrUnknownIcon means the name has no glyph. ErrUnknownIcon = errors.New("foodsafety: unknown icon") )
Sentinel errors, so callers can branch with errors.Is rather than matching on message text.
Functions ¶
func AllergenKeys ¶
AllergenKeys returns every selectable allergen key, in canonical order.
Keys are locale-independent, so this reads the structural file rather than taking a locale.
func CodeScheme ¶
CodeScheme returns the scheme these codes belong to.
func DeclarationKeys ¶
DeclarationKeys returns every declaration key, in canonical order.
func IconToSVG ¶
func IconToSVG(name string, opts SVGOptions) (string, error)
IconToSVG returns the glyph as an <svg> string, for anything that interpolates markup — templates, e-mail, PDF.
It returns an error wrapping ErrUnknownIcon if the name has no glyph.
func IsAllergenKey ¶
IsAllergenKey reports whether value is a current allergen key. Retired keys return false.
func IsDeclarationKey ¶
IsDeclarationKey reports whether value is a current declaration key.
func LoadDataset ¶
LoadDataset returns the raw JSON for one of the packaged files, for tooling that wants the dataset rather than resolved values.
Valid names are "allergens.json", "declarations.json", "codes.json" and "icons.json".
Types ¶
type Allergen ¶
type Allergen struct {
// Key is the stored identifier, e.g. "WHEAT". This is what a product row
// holds.
Key string `json:"key"`
// Group is its LMIV group, e.g. "CEREALS". Twelve groups are also
// selectable keys; CEREALS and TREE_NUTS are display-only, because the law
// requires naming the specific grain or nut.
Group string `json:"group"`
// IsMember is true when this key is one member of a multi-member group.
IsMember bool `json:"isMember"`
// Icon is the glyph name, e.g. "cereals".
Icon string `json:"icon"`
// Name is the short label, e.g. "Wheat".
Name string `json:"name"`
// Declaration is the sentence with legal force. This is what must reach
// the guest.
Declaration string `json:"declaration"`
// Description is a longer explanation, for tooltips and help text.
Description string `json:"description"`
}
Allergen is one allergen, resolved for a locale.
type Codes ¶
type Codes struct {
Scheme string `json:"scheme"`
Convention string `json:"convention"`
// Allergens maps an allergen key to its printable code, e.g. WHEAT → A6.
Allergens map[string]string `json:"allergens"`
// Declarations maps a declaration key to its code, e.g. SWEETENERS → 12.
Declarations map[string]string `json:"declarations"`
}
Codes is the footnote-code scheme: letters for allergens, numbers for declarations.
type Declaration ¶
type Declaration struct {
Key string `json:"key"`
// Category is one of ADDITIVE, BEVERAGE, WARNING, PRODUCT.
Category string `json:"category"`
// Icon is the glyph name. All declarations share one generic glyph.
Icon string `json:"icon"`
Name string `json:"name"`
Description string `json:"description"`
}
Declaration is one additive, beverage or product note, resolved for a locale.
type Disclosures ¶
type Disclosures struct {
Locale string `json:"locale"`
// FallbackLocale is the locale this bundle falls back to for anything it
// does not itself carry.
FallbackLocale string `json:"fallbackLocale"`
Allergens []Allergen `json:"allergens"`
Declarations []Declaration `json:"declarations"`
}
Disclosures is every disclosure for one locale, ready to render.
func GetDisclosures ¶
func GetDisclosures(locale string) (Disclosures, error)
GetDisclosures returns every disclosure for locale, ready to render.
It returns an error wrapping ErrUnsupportedLocale rather than falling back: a silently wrong language on an allergen panel is worse than a loud failure. The caller knows which locales it supports, and IsLocale is there to ask.
type Icon ¶
Icon is a glyph as data, for callers that build shapes rather than markup.
type IconNode ¶
type IconNode struct {
// Tag is "path" or "circle".
Tag string
// Attributes are named in SVG spelling (fill-rule, not fillRule).
Attributes map[string]string
}
IconNode is a single shape in a glyph.
type SVGOptions ¶
type SVGOptions struct {
// Size is the rendered width and height in px. Zero means 24.
Size int
// Class is added to the root element.
Class string
// Title gives the glyph an accessible name and role="img".
//
// Leave it empty when the declaration text sits beside the icon: then the
// glyph is decoration, stays aria-hidden, and the text carries the meaning.
// That is the correct default on a legal surface.
Title string
}
SVGOptions tunes IconToSVG.