5f4f1f7508
Añade campos params y output al frontmatter YAML de las 506 funciones del registry. Cada parámetro tiene descripción semántica (qué representa, unidades, rango típico) y cada función describe qué produce su output. Permite a agentes razonar sobre cadenas de composición (ej: prices → log_return → sharpe_ratio) sin leer código.
2.2 KiB
2.2 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| t | function | py | core | 1.0.0 | impure | def t(key: str, locale: str | None = None, **kwargs) -> str | Traduce una clave con dot-path notation al idioma activo. Prioridad: parametro locale > thread-local > default. Soporta interpolacion {variable}. Fallback al locale default si la clave no existe; si tampoco existe, retorna la key. |
|
false | error_go_core |
|
|
String traducido e interpolado, o la key si no se encuentra traducción | true |
|
python/functions/core/t_test.py | python/functions/core/t.py |
Ejemplo
from t import t, _set_translations
translations = {
"en": {
"report": {
"sectionStart": "Generating section: {title}",
"done": "Done"
}
},
"es": {
"report": {
"done": "Listo"
}
}
}
_set_translations(translations, default_locale="en")
t("report.sectionStart", locale="en", title="Introduction")
# → "Generating section: Introduction"
t("report.done", locale="es")
# → "Listo"
t("report.sectionStart", locale="es", title="Intro")
# → "Generating section: Intro" (fallback a en)
t("nonexistent.key", locale="en")
# → "nonexistent.key"
Notas
Lee estado global (modulo-level _translations y _locale_local thread-local), por eso es impura. Configurar con _set_translations() al inicio de la aplicacion y _set_locale() por thread/request. La interpolacion usa str.format(**kwargs) — si hay un placeholder faltante, retorna el string sin interpolar para no romper el flujo. Inspirada conceptualmente en el modulo locale.py de MiroFish (AGPL-3.0); reimplementada desde cero.