infrastructure tier

infrastructure-translate

Provider-agnostic text translation: Translator trait, ordered fallback chain, content-addressed cache key (composes infrastructure-ai)

Provider-agnostic text translation: Translator trait, ordered fallback chain, content-addressed cache key (composes infrastructure-ai)

Tierinfrastructure
Roleunclassified (baselined)
Pathcrates/infrastructure/translate
Edition2021
Targetsinfrastructure_translate
Public items16 across 0 modules
Tests22

What it is for

infrastructure-translate — provider-agnostic text translation.

Sprint 0.65. A generic translation engine lifted up so application-cms, baloo, happydiving, and spanish-novels share one implementation instead of each re-authoring it. This crate owns the Translator trait, the ordered FallbackTranslator, is_garbage detection, normalize_source, and content-addressed cache_key derivation.

I/O-bound backends (AiTranslator over infrastructure-ai, MyMemoryTranslator HTTP) and the Postgres translation cache land in later tasks under the Gate 2.1 DB/IO exception — this slice is the pure, decidable core.

Capabilities

crate root

infrastructure-translate — provider-agnostic text translation.

Item
fn normalize_source(s : & str) -> String
fn is_garbage(source : & str, output : & str) -> bool
fn cache_key(req : & TranslateRequest, provider : & ProviderId, prompt_version : u32) -> String

CacheScope

infrastructure-translate — provider-agnostic text translation.

Item
pub enum CacheScope

FallbackTranslator

infrastructure-translate — provider-agnostic text translation.

Item
pub struct FallbackTranslator
FallbackTranslator :: fn new(translators : Vec <Box <dyn Translator>>) -> Self
FallbackTranslator :: fn id(& self) -> ProviderId
FallbackTranslator :: async fn translate(& self, req : & TranslateRequest) -> Result <TranslateOutput, TranslateError>

Provenance

infrastructure-translate — provider-agnostic text translation.

Item
pub struct Provenance

ProviderId

infrastructure-translate — provider-agnostic text translation.

Item
pub struct ProviderId
ProviderId :: fn new(family : impl Into <String>, model : impl Into <String>) -> Self

Register

infrastructure-translate — provider-agnostic text translation.

Item
pub enum Register

TranslateError

infrastructure-translate — provider-agnostic text translation.

Item
pub enum TranslateError

TranslateOutput

infrastructure-translate — provider-agnostic text translation.

Item
pub struct TranslateOutput

TranslateRequest

infrastructure-translate — provider-agnostic text translation.

Item
pub struct TranslateRequest

Translator

infrastructure-translate — provider-agnostic text translation.

Item
pub trait Translator

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

No public modules: the crate root is its whole surface.

Public surface

`crate root`

ItemWhat it is
pub enum RegisterFormality/register of the requested translation
pub enum CacheScopeCache isolation boundary
pub struct ProviderIdProvider family + exact model identity
ProviderId :: fn new(family : impl Into <String>, model : impl Into <String>) -> Self
pub struct ProvenanceProvenance recorded with every translation output.
pub struct TranslateRequestA request to translate one block of text.
pub struct TranslateOutputA successful translation plus its provenance.
pub enum TranslateErrorFailure modes of a translation attempt.
pub trait TranslatorA translation backend.
fn normalize_source(s : & str) -> StringCollapse internal whitespace runs to single spaces and trim the ends, so a cache key is stable across cosmetic whitespace differences in the source.
fn is_garbage(source : & str, output : & str) -> boolDetect unusable translator output: empty/whitespace, an echo of the source, or markdown code-fence leakage
fn cache_key(req : & TranslateRequest, provider : & ProviderId, prompt_version : u32) -> StringContent-addressed cache key over every dimension that can change the output (Gate 1.5 Q2: scope, provider+model, prompt_version, lang pair, glossary, register, normalized source)
pub struct FallbackTranslatorTries each translator in order, skipping any that errors or returns garbage, returning the first usable output
FallbackTranslator :: fn new(translators : Vec <Box <dyn Translator>>) -> Self
FallbackTranslator :: fn id(& self) -> ProviderId
FallbackTranslator :: async fn translate(& self, req : & TranslateRequest) -> Result <TranslateOutput, TranslateError>

Re-exports. Exported here, defined elsewhere.

ExportDefined in
AiTranslatorai::AiTranslator
MyMemoryTranslatormymemory::MyMemoryTranslator
PgTranslationCachecache::PgTranslationCache
{CachingTranslator,TranslationCache}cache::{CachingTranslator,TranslationCache}
{is_stale,source_sha256,Origin}origin::{is_stale,source_sha256,Origin}
{mymemory_url,parse_mymemory_response}mymemory::{mymemory_url,parse_mymemory_response}

Boundary

Depends on no other workspace tier.

Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)infrastructure
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/infrastructure/translate
Vocabulary in force (lexicon)current

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`infrastructure-ai`infrastructurenoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
hex^0.4noalways
reqwest^0.12jsonyesalways
serde^1derivenoalways
serde_json^1noalways
sha2^0.10noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonyesalways
thiserror^2noalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1fullnoalways
tokio-test^0.4noalways

Build. None.

Depended on by. 1 workspace crate.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_cms["application-cms"] -->|uses| SELF
  SELF["infrastructure-translate"]
  SELF -->|runtime| n_infrastructure_ai["infrastructure-ai"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

FeatureEnablesOn by default
defaultyes
httpdep:reqwestno
postgresdep:sqlxno
flowchart LR
  n_default["default"]
  n_http["http"] --> n_dep_reqwest["dep:reqwest"]
  n_postgres["postgres"] --> n_dep_sqlx["dep:sqlx"]

Targets

KindNameSource
libinfrastructure_translate`src/lib.rs`

Error model

Error typeNamed by
TranslateErrordeclared, no public signature returns it

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimenone detected
database accessyes
network I/Oyes
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

1 workspace crate depends on this one: application-cms.

Verification

KindCount
Unit tests22
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root1208

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc1216
Public modules with a //! block00
pie showData
    title Public items with rustdoc
    "Documented" : 12
    "No rustdoc detected" : 4

Metrics

MetricValue
Rust source files5
Source lines993
Code lines797
Public API items16
Public modules0
Tests22
Examples0
Cargo features3
Direct runtime dependencies9
Workspace reverse dependencies1
pie showData
    title Public API by kind
    "enum" : 3
    "function" : 3
    "method" : 4
    "struct" : 5
    "trait" : 1
pie showData
    title Rust source composition
    "Code" : 797
    "Blank or comment" : 196

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

All infrastructure · Manual