provisioning-outreach/presentations/rust-laspalmas-250926/auroraframe/framework/schemas/i18n-config.k

102 lines
No EOL
4.1 KiB
Text

# AuroraFrame i18n Configuration Schema
schema LocaleConfig:
"""Configuration for a single locale"""
code: str # Language code (en-US, es-ES, etc.)
name: str # Human readable name
direction: "ltr" | "rtl" = "ltr" # Text direction
fallback?: str # Fallback locale code
region?: str # Geographic region
script?: str # Writing script
enabled: bool = True # Whether this locale is active
schema I18nGlobalConfig:
"""Site-wide internationalization configuration"""
default_locale: str # Default locale for the site
available_locales: [LocaleConfig] # All available locales
fallback_chain: [str] # Global fallback order
# Global locale file paths
global_locales_dir: str = "locales/global"
page_locales_dir: str = "locales/pages"
# Build settings
generate_locale_routes: bool = True # Generate /en/, /es/ routes
locale_in_url: bool = True # Include locale in URLs
locale_detection: [str] = ["url", "cookie", "header", "default"]
# Performance settings
bundle_splitting: "per-page" | "global" | "hybrid" = "hybrid"
preload_locales: [str] = [] # Locales to preload
lazy_load_pages: bool = True # Load page locales on demand
schema I18nPageConfig:
"""Page-specific internationalization configuration"""
enabled: bool = True # Enable i18n for this page
locales?: [str] # Override available locales for this page
default_locale?: str # Override default locale
namespace?: str # Locale namespace for this page
# Page-specific locale files
locale_files: [str] = [] # Additional FTL files to load
extends_global: bool = True # Inherit global locales
override_global: bool = False # Can override global messages
# Page routing
route_template?: str # Custom route template: "/{locale}/blog/{slug}"
canonical_locale?: str # Canonical locale for this page
schema I18nBuildConfig:
"""Build-time i18n configuration"""
validate_messages: bool = True # Validate all message references
extract_strings: bool = False # Auto-extract translatable strings
generate_typing: bool = True # Generate TypeScript/KCL types
# Output settings
output_format: "json" | "ftl" | "both" = "both"
minify_output: bool = True # Minify generated locale files
# AI assistance
ai_translation: bool = False # Enable AI-powered translations
ai_validation: bool = True # Validate translations with AI
missing_key_strategy: "warn" | "error" | "generate" = "warn"
schema SiteConfig:
"""Extended site configuration with i18n"""
# ... existing site config ...
i18n: I18nGlobalConfig
schema PageConfig:
"""Extended page configuration with i18n"""
# ... existing page config ...
i18n?: I18nPageConfig
# Validation rules
check SiteI18nValidation:
"""Validate site-wide i18n configuration"""
# Default locale must be in available locales
site.i18n.default_locale in [locale.code for locale in site.i18n.available_locales]
# Fallback chain locales must exist
all fallback in site.i18n.fallback_chain {
fallback in [locale.code for locale in site.i18n.available_locales]
}
# Preload locales must be available
all preload in site.i18n.preload_locales {
preload in [locale.code for locale in site.i18n.available_locales]
}
check PageI18nValidation:
"""Validate page-specific i18n configuration"""
# Page locales must be subset of site locales (if specified)
if page.i18n?.locales {
all page_locale in page.i18n.locales {
page_locale in [locale.code for locale in site.i18n.available_locales]
}
}
# Page default locale must be available (if specified)
if page.i18n?.default_locale {
page.i18n.default_locale in [locale.code for locale in site.i18n.available_locales]
}