CodeSampleX

Sample

golang.org/x/text v0.34.0: message.SetString

Verified sample for golang golang.org/x/text v0.34.0: message.SetString. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:ad94db0f1475b495c1a20b896583190fa6adb71f7f5e74ac80e64e7c61d3646b

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-26

Case

HOW
Goal
verify message.SetString in pkg:golang/golang.org/x/text@v0.34.0
Packages
Symbols
  • message.SetString
Environment
go 1.26.6
Created
2026-08-26T06:09:45Z

Contract

  1. message.SetString registers a translation string for a given language tag and message key
  2. message.NewPrinter falls back to the default message key when no translation is registered for the requested language tag
  3. message.SetString allows positional format specifiers to reorder arguments across locales
  4. message.SetString overwrites previous translations when called again with the same language tag and key
  5. message.NewPrinter resolves to parent language tag translations when exact regional tag translation is not explicitly registered

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify message.SetString in pkg:golang/golang.org/x/text@v0.34.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.34.0
Demonstrate these symbols/APIs:
  - message.SetString

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:f1517de86d51963040bb621fb28f0327a9b46bfe4e7e82fe73077a199ec7ef19","contract":["message.SetString registers a translation string for a given language tag and message key","message.NewPrinter falls back to the default message key when no translation is registered for the requested language tag","message.SetString allows positional format specifiers to reorder arguments across locales","message.SetString overwrites previous translations when called again with the same language tag and key","message.NewPrinter resolves to parent language tag translations when exact regional tag translation is not explicitly registered"],"goal":"verify message.SetString in pkg:golang/golang.org/x/text@v0.34.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.34.0"],"schemaVersion":1,"symbols":["message.SetString"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/text@v0.34.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.34.0","symbols":["message.SetString"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require golang.org/x/text v0.34.0
go.sum
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
main.go
package main

import (
	"fmt"

	"golang.org/x/text/language"
	"golang.org/x/text/message"
)

func main() {
	// Register localized message strings for different language tags
	_ = message.SetString(language.English, "Hello %s!", "Hello %s!")
	_ = message.SetString(language.French, "Hello %s!", "Bonjour %s!")
	_ = message.SetString(language.German, "%s has %d items", "%[2]d Artikel für %[1]s")

	// Create localized printers for each language
	pEn := message.NewPrinter(language.English)
	pFr := message.NewPrinter(language.French)
	pDe := message.NewPrinter(language.German)

	fmt.Println(pEn.Sprintf("Hello %s!", "Alice"))
	fmt.Println(pFr.Sprintf("Hello %s!", "Alice"))
	fmt.Println(pDe.Sprintf("%s has %d items", "Bob", 3))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify message.SetString in pkg:golang/golang.org/x/text@v0.34.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.34.0"
  ],
  "symbols": [
    "message.SetString"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/text/language"
	"golang.org/x/text/message"
)

func main() {
	// 1. message.SetString registers a translation string for a given language tag and message key
	err := message.SetString(language.French, "greeting %s", "Bonjour %s")
	if err != nil {
		fmt.Fprintf(os.Stderr, "message.SetString failed: %v\n", err)
		os.Exit(1)
	}

	pFr := message.NewPrinter(language.French)
	gotFr := pFr.Sprintf("greeting %s", "Monde")
	if gotFr != "Bonjour Monde" {
		fmt.Fprintf(os.Stderr, "Expected 'Bonjour Monde', got: %q\n", gotFr)
		os.Exit(1)
	}

	// 2. message.NewPrinter falls back to the default message key when no translation is registered for the requested language tag
	pJa := message.NewPrinter(language.Japanese)
	gotJa := pJa.Sprintf("greeting %s", "World")
	if gotJa != "greeting World" {
		fmt.Fprintf(os.Stderr, "Expected fallback 'greeting World', got: %q\n", gotJa)
		os.Exit(1)
	}

	// 3. message.SetString allows positional format specifiers to reorder arguments across locales
	err = message.SetString(language.German, "%s has %d apples", "%[2]d Äpfel gehören %[1]s")
	if err != nil {
		fmt.Fprintf(os.Stderr, "message.SetString with reordered format failed: %v\n", err)
		os.Exit(1)
	}

	pDe := message.NewPrinter(language.German)
	gotDe := pDe.Sprintf("%s has %d apples", "Hans", 5)
	if gotDe != "5 Äpfel gehören Hans" {
		fmt.Fprintf(os.Stderr, "Expected '5 Äpfel gehören Hans', got: %q\n", gotDe)
		os.Exit(1)
	}

	// 4. message.SetString overwrites previous translations when called again with the same language tag and key
	err = message.SetString(language.Spanish, "farewell", "Adiós")
	if err != nil {
		fmt.Fprintf(os.Stderr, "message.SetString initial Spanish failed: %v\n", err)
		os.Exit(1)
	}
	pEs := message.NewPrinter(language.Spanish)
	if pEs.Sprintf("farewell") != "Adiós" {
		fmt.Fprintf(os.Stderr, "Expected 'Adiós', got: %q\n", pEs.Sprintf("farewell"))
		os.Exit(1)
	}

	err = message.SetString(language.Spanish, "farewell", "Hasta luego")
	if err != nil {
		fmt.Fprintf(os.Stderr, "message.SetString overwrite Spanish failed: %v\n", err)
		os.Exit(1)
	}
	gotEsOverwritten := pEs.Sprintf("farewell")
	if gotEsOverwritten != "Hasta luego" {
		fmt.Fprintf(os.Stderr, "Expected overwritten translation 'Hasta luego', got: %q\n", gotEsOverwritten)
		os.Exit(1)
	}

	// 5. message.NewPrinter resolves to parent language tag translations when exact regional tag translation is not explicitly registered
	err = message.SetString(language.English, "color_item", "colour")
	if err != nil {
		fmt.Fprintf(os.Stderr, "message.SetString base English failed: %v\n", err)
		os.Exit(1)
	}
	pGb := message.NewPrinter(language.BritishEnglish)
	gotGb := pGb.Sprintf("color_item")
	if gotGb != "colour" {
		fmt.Fprintf(os.Stderr, "Expected regional tag to resolve to base English 'colour', got: %q\n", gotGb)
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed.")
}

Origin Seeder

anonymous