Skip to content

feat(core): add supported languages and DEFAULT_LANGUAGE setting - #580

Open
abdulrafey1 wants to merge 1 commit into
refey/chore/lang-01-drop-system-promptfrom
refey/feat/lang-02-core-config
Open

feat(core): add supported languages and DEFAULT_LANGUAGE setting#580
abdulrafey1 wants to merge 1 commit into
refey/chore/lang-01-drop-system-promptfrom
refey/feat/lang-02-core-config

Conversation

@abdulrafey1

Copy link
Copy Markdown
Contributor

What

Adds the supported-language allowlist and the platform-wide DEFAULT_LANGUAGE setting that later work reads from.

Changes

  • feat(core): add LanguageInfo, SUPPORTED_LANGUAGES (en/es/fr) and is_supported_language to sparkth/core/config.py
  • feat(core): add Settings.DEFAULT_LANGUAGE, validated against the allowlist at startup
  • docs(core): document DEFAULT_LANGUAGE in the configuration reference and add it to .env

How to Test

  1. uv run pytest tests/core/test_language.py -q — 8 tests pass.
  2. Set DEFAULT_LANGUAGE=klingon in .env and start the app: it fails at startup with DEFAULT_LANGUAGE must be one of: en, es, fr rather than accepting the value.
  3. Restore DEFAULT_LANGUAGE=en and confirm the app boots.

Notes

New env var: DEFAULT_LANGUAGE (defaults to en, committed in .env). No migration, no API change.

Tags are BCP 47 (RFC 5646) and hyphenated — the form HTML lang, Accept-Language and the JS Intl API consume. The list is deliberately short: LLM output quality varies by language, so a language is added only once generated content in it has been reviewed by a speaker.

is_supported_language lives beside the allowlist so the membership rule has exactly one expression — Settings.DEFAULT_LANGUAGE's validator reuses it, which stops the platform default from ever accepting a value the API would reject.

This description was written with the assistance of an LLM (Claude).

Introduces the BCP 47 allowlist (en/es/fr) and the platform default used when a
user has not chosen a language. The default is validated against the allowlist so
a typo fails at startup instead of silently being accepted.

Membership is expressed once, as is_supported_language, and the DEFAULT_LANGUAGE
validator calls it rather than repeating the containment check. Both edges of the
allowlist — the platform default and, later, a user's own tag — therefore answer to
the same rule and cannot drift apart if it ever grows case folding or subtag
stripping. Matching is exact and case-sensitive today: "en-US" and "EN" are
unsupported, not normalised to "en".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant