Source code for aeat.application.user_profile._language_resolver
"""Active-profile output-language resolver wiring for ``core.i18n``.The ``core`` layer must not import application modules, so it resolvesthe active profile's ``preferences.output_language`` preference througha registered callback (see:func:`aeat.core.i18n.register_profile_language_resolver`).This module owns the application-side resolver and registers it as amodule-import side-effect. Importing it is cheap — every heavyweightimport (workflow persistence, orchestration) is deferred inside theresolver body so registration cannot trigger an import cascade."""from__future__importannotationsfrom...core.i18nimportregister_profile_language_resolver
[docs]defresolve_active_profile_output_language()->str|None:"""Return the active profile's ``preferences.output_language`` fact. Performs a pure read of workflow state — no mutation, no bucket events — and returns ``None`` when there is no active profile or no language fact, so the caller falls back to the settings default. When the bucket session is closed or cannot open, reads the bucket-local non-secret language hint instead of the encrypted profile envelope. """from...adapters.persistence.storage.master_keyimporthas_active_bucket_sessionifnothas_active_bucket_session():returnresolve_active_profile_output_language_hint()from..workflowimportworkflow_state_repositoryfrom._orchestrationimportfact_valuerecord=workflow_state_repository().load().active_profile_record()ifrecordisNone:returnNonereturnfact_value(record,"preferences.output_language")
[docs]defresolve_active_profile_output_language_hint()->str|None:"""Return the active bucket's last-known output-language hint, if present."""try:from...coreimportresolve_active_bucket_idbucket_id=resolve_active_bucket_id()ifbucket_idisNone:returnNonereturnresolve_profile_output_language_hint(bucket_id)exceptException:returnNone
[docs]defresolve_profile_output_language_hint(bucket_id:str)->str|None:"""Return a named bucket's last-known output-language hint, if present."""try:from...adapters.persistence.storage.bucketimportread_bucket_output_language_hintfrom...core.configimportload_settingstrimmed=bucket_id.strip()ifnottrimmed:returnNonereturnread_bucket_output_language_hint(storage_root=load_settings().aeat_local_storage_root,bucket_id=trimmed,)exceptException:returnNone
[docs]defregister_language_resolver()->None:"""Register :func:`resolve_active_profile_output_language` with ``core.i18n``. Replaces the prior module-import side-effect registration: callers now invoke this function from a known initialiser (the :mod:`aeat.application.user_profile` package import) so the registration point is explicit and greppable rather than hidden in a noqa-protected import line. """register_profile_language_resolver(resolve_active_profile_output_language)