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.3.0 covers all public
Translation.frameworksymbols in the current macOS SDK and adds a Tier-1async_apimodule for Future-based translation and availability workflows.
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.
Async API
Enable the async feature to use executor-agnostic futures backed by Swift Task thunks and doom-fish-utils completion helpers:
= { = "0.3", = ["async"] }
The async surface currently includes:
AsyncTranslationSession::translateAsyncTranslationSession::translationsAsyncTranslationSession::prepare_translationAsyncLanguageAvailability::statusAsyncLanguageAvailability::supported_languages
See examples/10_async_translate.rs and examples/11_async_availability.rs for end-to-end usage with pollster::block_on.
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_smoke10_async_translate(requires--features async)11_async_availability(requires--features async)
Run the sync examples with:
for; do
done
Run the async examples with:
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.