Files
fn_registry/python/functions/core/t.md
T
egutierrez 25a392df48 feat: funciones Python core — parsers, formatters, retry, serialización, LLM utils y más
178 archivos: módulo core.py actualizado + ~80 funciones nuevas con tests.
Incluye: parse_llm_json, extract_text_from_file, retry_with_backoff, circuit_breaker,
from_csv/to_csv, from_jsonl/to_jsonl, html_to_markdown, pdf_to_markdown, docx/epub/excel
converters, cache_decorator, react_loop, task_manager, template rendering, entre otros.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 17:11:21 +02:00

1.9 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, 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 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.
i18n
translation
locale
dot-path
interpolation
false error_go_core
threading
true
key existente retorna traduccion
key inexistente retorna la key
interpolacion de variables
dot-path profundo
fallback a locale default
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.