TranslationService
- class TranslationService
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Feature\ Translation Service
Language translation with quality control.
- translate ( string $text, string $targetLanguage, ?string $sourceLanguage = null, ?TranslationOptions $options = null) : TranslationResult
-
Translate text to target language.
- param string $text
-
Text to translate
- param string $targetLanguage
-
Target language code (e.g., 'de', 'fr')
- param string|null $sourceLanguage
-
Source language code (auto-detected if null)
- param TranslationOptions|null $options
-
Translation options
TranslationOptions fields:
formality: 'formal', 'informal', 'default'domain: 'technical', 'legal', 'medical', 'marketing', 'general'glossary: array of term translationspreserve_formatting: boolprovider,model: pin the provider / model for this callconfiguration: identifier of a storedLlmConfigurationwhose translator is used on the specialized-translator path (translateWithTranslator())
- Returns
-
TranslationResult
- translateForConfiguration ( string $text, string $targetLanguage, LlmConfiguration $configuration, ?string $sourceLanguage = null, ?TranslationOptions $options = null) : TranslationResult
-
Translate with a stored
LlmConfiguration's persona/tone.Unlike translate, this routes through
LlmServiceManager::chatWithConfiguration()so the configuration's storedsystem_prompt, model, provider and skills apply.translate()supplies its own system message and therefore short-circuitsMessageShaper::applySystemPrompt(), so a configuration'ssystem_promptnever reaches the model on that path. Here the translation task and constraints (target/source language, formality, glossary, "output only the translation") are layered into the user message instead, keeping the configuration'ssystem_promptas the system message.Mirrors
chatWithToolsForConfiguration()andembedForConfiguration().- param string $text
-
Text to translate
- param string $targetLanguage
-
Target language code (e.g., 'de', 'fr')
- param LlmConfiguration $configuration
-
The configuration whose persona/model drive the call
- param string|null $sourceLanguage
-
Source language code (auto-detected if null)
- param TranslationOptions|null $options
-
Translation options;
temperature,max_tokensandmodeloverride the configuration's stored defaults when set. Theproviderfield is ignored — the configuration selects the provider.
- Returns
-
TranslationResult
- translateBatch ( array $texts, string $targetLanguage, ?string $sourceLanguage = null, ?TranslationOptions $options = null) : array
-
Translate multiple texts.
- param array $texts
-
Array of texts
- param string $targetLanguage
-
Target language code
- param string|null $sourceLanguage
-
Source language code (auto-detected if null)
- param TranslationOptions|null $options
-
Translation options
- Returns
-
array<TranslationResult>
- detectLanguage ( string $text, ?TranslationOptions $options = null) : string
-
Detect the language of text.
- param string $text
-
Text to analyze
- param TranslationOptions|null $options
-
Translation options
- Returns
-
string Language code (ISO 639-1)
- scoreTranslationQuality ( string $sourceText, string $translatedText, string $targetLanguage, ?TranslationOptions $options = null) : float
-
Score translation quality.
- param string $sourceText
-
Original text
- param string $translatedText
-
Translated text
- param string $targetLanguage
-
Target language code
- param TranslationOptions|null $options
-
Translation options
- Returns
-
float Quality score (0.0 to 1.0)