The common case is the frequent, typical usage scenario an API should make especially easy. Keep advanced capabilities available without making ordinary operations harder. section 1.4.3
Translation API
A direct call such as TranslateText("Hello world", "es") serves the ordinary translation task. Requiring users to detect a language, select a model, and pass a model ID exposes unnecessary complexity. An optional modelId preserves advanced control without burdening typical callers. section 1.4.3
Apply the pattern by:
- Giving each distinct operation a method designed for its purpose, rather than hiding language detection inside translation. section 1.4.3
- Choosing references or inline data according to typical usage, resource size, query cost, and likely growth. section 4.2.2
Listing 1.3 Translating text to a target language (the common case)
function translateText(inputText: string,
targetLanguage: string,
modelId?: string): string {
return TranslateApi.TranslateText({
text: inputText,
targetLanguage: targetLanguage,
modelId: modelId,
});
}
Shows a common translation call with optional advanced model selection. section 1.4.3
