translation-rs
Safe Rust bindings for Apple's Translation.framework on macOS, plus typed language helpers for canonical language identifiers, language pairs, translation configuration state, translation responses, translation errors, and NaturalLanguage-backed language recognition.
Status: v0.2.0 covers all public
Translation.frameworksymbols in the current macOS SDK and organizes the crate into eight logical areas:TranslationSession,LanguageAvailability,TranslationConfiguration,TranslationResponse,TranslationError,Language,LanguagePair, andLanguageRecognition.
Quick start
use *;
Highlights
LanguageandLanguagePairwrappers that canonicalizeLocale.Languageidentifiers through the Swift bridge.LanguageAvailabilityaccess tosupportedLanguages, pair status, and text status, including optional target-language queries.TranslationConfigurationfor mutable source/target configuration state and invalidation version tracking.TranslationSessionwithcan_request_downloads,is_ready,cancel, eager batch translation, and streamingtranslate(batch:)iteration.TranslationRequestsetters plusTranslationResponseconstructors, serde support, and typed language accessors.TranslationErrorvariants that preserve botherrorDescriptionandfailureReasonfromTranslation.frameworkerrors.recognize_language/detect_languagefallback powered byNLLanguageRecognizer.
Availability
- The crate weak-links
Translation.framework, so the typedLanguage,LanguagePair,TranslationConfiguration,TranslationResponse, andLanguageRecognitionhelpers work on macOS 14+. LanguageAvailabilityrequires macOS 15+.- Manual
TranslationSessionconstruction is currently available on macOS 26+ throughTranslationSession(installedSource:target:); the crate surfaces those APIs and returns structuredTranslationErrorvalues on older systems.
Examples
The crate ships numbered examples for every logical area plus an end-to-end framework smoke test:
01_language_roundtrip02_language_pair_roundtrip03_translation_error_messages04_language_availability_smoke05_translation_configuration_lifecycle06_translation_response_roundtrip07_language_recognition_smoke08_translation_session_smoke09_framework_smoke
Run them all with:
for; do ; done
Coverage
See COVERAGE.md for the API-by-API audit against the active macOS SDK.
License
Licensed under either Apache-2.0 or MIT at your option.