What Programming Languages Does Tolaria Support?
Tolaria supports 15 UI interface languages and automatically detects 8 programming languages for syntax highlighting in code blocks, including Python, TypeScript, JavaScript, and SQL.
Tolaria is an open-source rich-text editor maintained by refactoringhq. The codebase defines language capabilities across two distinct layers: interface localization handled in src/lib/i18n.ts and code block language inference implemented in src/utils/codeBlockLanguage.ts.
UI Localization Languages
Tolaria ships with complete localization support for 15 distinct locales. These definitions reside in the APP_LOCALES array inside src/lib/i18n.ts.
The supported interface languages are:
en— English (default)it-IT— Italianfr-FR— Frenchde-DE— Germanru-RU— Russianes-ES— Spanish (Spain)pt-BR— Portuguese (Brazil)pt-PT— Portuguese (Portugal)es-419— Spanish (Latin America)zh-CN— Chinese (Simplified)zh-TW— Chinese (Traditional)ja-JP— Japaneseko-KR— Koreanvi— Vietnamesepl-PL— Polish
Locale resolution occurs via the resolveEffectiveLocale() function, which checks for explicit user preferences first, falls back to browser/system detection, and ultimately defaults to English. Translation catalogs for each locale live under src/lib/locales/*.json and load lazily via Vite’s import.meta.glob.
Programming Languages for Code Blocks
Tolaria’s editor uses the BlockNote component with the Shiki highlighter. When users paste or type code without specifying a language, Tolaria runs an inference step to detect the correct syntax highlighter to apply.
The inferCodeBlockLanguage() function in src/utils/codeBlockLanguage.ts recognizes the following languages through regex pattern matching:
| Language | Detection Pattern |
|---|---|
| html | HTML-style markup (<tag>) |
| python | Function definitions (def ...:), class definitions, or import statements |
| shellscript | Shebang lines or common shell commands (pnpm, npm, git, cd, echo) |
| typescript | TypeScript-specific keywords (interface, enum, implements, namespace) or type annotations |
| javascript | Generic JS keywords (import, export, const, let, function, arrow functions) |
| sql | Query statements (SELECT, WITH, INSERT, UPDATE, DELETE with FROM) |
| yaml | Key-value pairs (key: value) |
| json | Valid JSON structure (detected via JSON.parse rather than regex) |
How Language Detection Works
The inference algorithm first trims the snippet, checks if it is valid JSON, then scans against the LANGUAGE_PATTERNS array. This array is defined in src/utils/codeBlockLanguage.ts as follows:
const LANGUAGE_PATTERNS: Array<[string, RegExp]> = [
['html', /^\s*<[/!A-Za-z][\s\S]*>\s*$/u],
['python', /^\s*(?:def|class)\s+\w+.*:\s*$/mu],
['python', /^\s*(?:from\s+\w+(?:\.\w+)*\s+import|import\s+\w+)/mu],
['shellscript', /^\s*(?:#!.*\b(?:bash|sh|zsh)\b|(?:pnpm|npm|yarn|git|cd|echo|export)\b)/mu],
['typescript', /\b(?:interface|type|enum|implements|readonly|namespace|declare)\b/u],
['typescript', /\b(?:const|let|var|function)\s+\w+\s*(?:<[^>]+>)?\([^)]*:\s*[^)]*\)/u],
['typescript', /:\s*(?:string|number|boolean|unknown|never|void|null|undefined|Record<|[A-Z]\w*(?:\[\])?)\b/u],
['javascript', /\b(?:import|export|const|let|var|function|return)\b|=>/u],
['sql', /^\s*(?:SELECT|WITH|INSERT|UPDATE|DELETE)\b[\s\S]*\bFROM\b/iu],
['yaml', /^\s*[\w-]+\s*:\s*[\s\S]*$/u],
];
The detected language is then attached to the block’s props.language property so Shiki can apply the correct tokenization.
Practical Implementation Example
Here is how to interact with both language systems programmatically:
import { resolveEffectiveLocale, APP_LOCALES } from '@/lib/i18n';
import { inferCodeBlockLanguage } from '@/utils/codeBlockLanguage';
// Retrieve the effective UI locale for the current user
const userPref = 'zh-CN';
const effectiveLocale = resolveEffectiveLocale(userPref);
console.log('UI locale:', effectiveLocale); // → 'zh-CN'
// Access the complete list of supported UI languages
console.log('Available locales:', APP_LOCALES);
// Infer programming language from raw code snippet
const snippet = `
def hello(name):
print(f"Hello {name}")
`;
const inferred = inferCodeBlockLanguage(snippet);
console.log('Detected language:', inferred); // → 'python'
Summary
- Tolaria supports 15 UI languages defined in
src/lib/i18n.ts, including English, Chinese (Simplified and Traditional), Japanese, Korean, and major European languages. - Code block language detection covers 8 programming languages via
src/utils/codeBlockLanguage.ts: HTML, Python, shellscript, TypeScript, JavaScript, SQL, YAML, and JSON. - The
resolveEffectiveLocale()function handles locale fallback logic from user preferences → browser detection → English default. - The
inferCodeBlockLanguage()function uses regex pattern matching against theLANGUAGE_PATTERNSarray to automatically set syntax highlighting when no language is explicitly specified. - BlockNote bundles additional languages via Shiki, but Tolaria only actively infers the eight languages listed above for automatic detection.
Frequently Asked Questions
How many interface languages does Tolaria support?
Tolaria ships with 15 UI localization languages as defined in the APP_LOCALES array in src/lib/i18n.ts. These include English (default), Italian, French, German, Russian, Spanish (Spain and Latin America variants), Portuguese (Brazil and Portugal), Chinese (Simplified and Traditional), Japanese, Korean, Vietnamese, and Polish.
Which programming languages can Tolaria auto-detect in code blocks?
Tolaria automatically detects 8 programming languages: HTML, Python, shellscript (bash/sh/zsh), TypeScript, JavaScript, SQL, YAML, and JSON. Detection occurs through the inferCodeBlockLanguage() function in src/utils/codeBlockLanguage.ts, which scans content against predefined regex patterns. Note that BlockNote (via Shiki) supports many more languages for highlighting, but Tolaria only actively infers these eight when a code block lacks an explicit language tag.
How does Tolaria determine which programming language a code block contains?
The editor first trims the code snippet and checks if it is valid JSON. If not, it iterates through the LANGUAGE_PATTERNS array in src/utils/codeBlockLanguage.ts, testing the content against regex patterns for TypeScript-specific syntax, Python function definitions, SQL query structures, and other language markers. The first matching pattern determines the assigned language.
Can I extend Tolaria to support additional programming languages?
Yes. While the Shiki highlighter bundled with BlockNote already supports hundreds of languages, you can add automatic detection for additional languages by extending the LANGUAGE_PATTERNS array in src/utils/codeBlockLanguage.ts. For UI localization, you can add new locales by extending APP_LOCALES in src/lib/i18n.ts and adding corresponding translation files to src/lib/locales/.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →