Elektrine lite

← Feed

@normplum@fosstodon.org

Post #1158408

2026-04-09 11:25 UTC

Is there a way in #Hugo (or #Go?) to format a string to be singular when there's only one thing? E.g. "<p>{{ $videos | len }} videos</p>" sometimes outputs "1 videos". Is there an easy way to make it say "1 video" instead? @gohugoio #WebDev #GoLang

Replies (2)

  • @orsinium@fosstodon.org 2026-04-09 14:04

    @normplum@fosstodon.org i'd just use if-else. but the "proper" way is to use translations, then it can handle language-specific pluralization rules: https://gohugo.io/functions/lang/translate/#translations-with-pluralization

    Open ##2898686

  • @harry_wood@en.osm.town 2026-04-09 14:44

    @normplum@fosstodon.org In ruby it's called "inflectors", and I see somebody's made an "inflectors" package in go: https://pkg.go.dev/github.com/tangzero/inflector

    Open ##2898687