Mistral AI
AI translation with Mistral and Lingo.dev Compiler
What is Mistral AI?
Mistral AI is a French artificial intelligence company specializing in developing open-weight large language models, designed to be efficient, customizable, and accessible for a wide range of applications. They focus on transparency and performance, releasing models that can run efficiently on smaller hardware compared to many competitors.
Setting the API Key
Mistral AI requires an API key to authenticate requests from Lingo.dev Compiler. Choose the setup method that best fits your workflow:
Option 1: Environment Variable (Terminal)
Best for quick experiments and testing without modifying any files.
Set the key directly in your terminal session:
export MISTRAL_API_KEY="your-api-key-here"
This key will only be available until you close your terminal window.
Option 2: Project Configuration (.env)
Best for project-specific configuration and team environments where each project may use different credentials.
Create a .env
file in your project root:
touch .env
Add the following line to the file:
MISTRAL_API_KEY="your-api-key-here"
Lingo.dev Compiler checks for environment files in this priority order:
.env.development
(highest priority).env.local
.env
(lowest priority)
Values in higher-priority files override those in lower-priority files.
Option 3: Global Configuration (User Settings)
Best for individual developers who want to use the same API key across all their projects.
Create a configuration file in your home directory:
touch ~/.lingodotdevrc
Add the following content to the file:
[llm]
mistralApiKey="your-api-key-here"
This configuration persists across all terminal sessions and projects on your machine.
Configuration Priority
When multiple configuration methods are used, Lingo.dev Compiler checks for API keys in this order:
- Environment variables (highest priority)
- Project .env files (in their own priority order)
- User configuration file
~/.lingodotdevrc
(lowest priority)
The first valid API key that's found is used.
Using Mistral AI
To enable Mistral AI, set the models
property in the compiler options:
import react from "@vitejs/plugin-react";
import lingoCompiler from "lingo.dev/compiler";
import { type UserConfig } from "vite";
// https://vite.dev/config/
const viteConfig: UserConfig = {
plugins: [react()],
};
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja"],
rsc: false,
useDirective: false,
debug: false,
models: {
"*:*": "mistral:mistral-large-latest",
},
});
export default withLingo(viteConfig);
The property accepts an object where:
- the keys are pairs of source and target locales, with
*
representing any locale - the values are model identifiers (e.g.,
mistral:mistral-large-latest
)
You can use Mistral AI to translate:
- between all locales
- from a specific source locale
- to a specific target locale
- between a specific source and target locale
Translating all locales
Use the wildcard pattern *:*
to apply the same Mistral model for all translation pairs:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Use Mistral Large for all translation pairs
"*:*": "mistral:mistral-large-latest",
},
});
Translating from a specific source locale
Use a specific source locale with wildcard target to apply a model for all translations from that source:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Use Mistral Large for all translations from English
"en:*": "mistral:mistral-large-latest",
// Use Mixtral for translations from Spanish to any language
"es:*": "mistral:mixtral-8x7b",
// Fallback for other source languages
"*:*": "mistral:mistral-small-latest",
},
});
Translating to a specific target locale
Use a wildcard source with specific target locale to apply a model for all translations to that target:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Use specialized model for translations to Japanese
"*:ja": "mistral:mistral-large-latest",
// Use Mixtral for translations to Chinese
"*:zh": "mistral:mixtral-8x22b",
// Use Mistral Large for translations to French (Mistral's strength)
"*:fr": "mistral:mistral-large-latest",
// Default for other target languages
"*:*": "mistral:mistral-small-latest",
},
});
Translating between specific locales
Define exact source-target pairs for fine-grained control over which model handles specific language combinations:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Specific pairs with optimal models
"en:es": "mistral:mistral-small-latest", // English to Spanish
"en:ja": "mistral:mistral-large-latest", // English to Japanese
"en:zh": "mistral:mixtral-8x22b", // English to Chinese
"en:fr": "mistral:mistral-large-latest", // English to French (excellence)
"es:en": "mistral:mistral-nemo", // Spanish to English
"fr:en": "mistral:mistral-medium-latest", // French to English
"de:en": "mistral:codestral", // German to English (technical)
// Fallback for unspecified pairs
"*:*": "mistral:mistral-small-latest",
},
});