Configuration
This chapter documents all configuration options for the translation pipeline and how they affect input/output directories, providers, and the Docara build.
Minimal config (example)
<?php
return [
'source_dir' => __DIR__ . '/source/',
'target_lang' => 'en', // base locale (source of truth)
'main' => __DIR__ . 'configuration.md/', // project root
'cache_dir' => 'temp/',
'frontMatter' => ['title', 'description'],
'languages' => ['ru'], // target locales to generate
'output_dir' => __DIR__ . '/source',
'preserve_structure' => true,
];
Keys & semantics
source_dir (string, required)
Absolute path to your content root. The translator scans locale folders inside it.
Convention: docs per locale live under source/_docs-<locale> (e.g., _docs-en, _docs-ru).
target_lang (string, required)
The base locale to read from (e.g., en). Files in source/_docs-<target_lang> are treated as the source of truth.
Name is historical; think of it as
base_lang.
languages (string[], required)
List of target locales to produce (e.g., ['ru', 'de']). For each language, the translator writes/updates
source/_docs-<lang>.
output_dir (string, required)
Root path where localized trees are written. Normally the same as source_dir (so folders become siblings like
_docs-en, _docs-ru).
preserve_structure (bool, default: true)
When true, the directory/file structure under _docs-<target_lang> is mirrored into each target locale folder.
cache_dir (string, required)
Relative (to main) or absolute path for translation caches and runtime config.
Layout (relative to main):
!folders
- {$CACHE_DIR}
- translations -- translate_{$LANG}.json (key→translation cache) -- hash.json (checksum/housekeeping) -- .config.json (generated locales map for Docara) !endfolders
frontMatter (string[], optional)
List of front matter keys to translate (e.g., ['title','description']). Only these keys are sent to the provider.
main (string, required)
Project root; used to resolve cache_dir and other relative paths.
Environment variables (provider)
The Azure Translator provider expects the following in your .env:
AZURE_KEY=...
AZURE_REGION=...
AZURE_ENDPOINT=https://api.cognitive.microsofttranslator.com
The CLI (
bin/translate) loads.envbefore running. Ensure the keys are present in your build environment.
Directory conventions
!folders
-
source
- docs (default folder)
- en (default lang)
- ...
- ru (other locales)
- ... !endfolders
- en (default lang)
- docs (default folder)
-
Input:
source/{$DOCS_DIR}/{$lang} -
Output:
source/{$DOCS_DIR}/{$lang}for each entry inlanguages
File types translated
- Markdown/MDX (
.md), front matter keys listed infrontMatter - Language packs:
.lang.php,.settings.php(mirrored per locale)
The Markdown translator is AST-aware: only text nodes are translated; code blocks, inline code, links, and custom tags remain intact.
Docara integration (locales discovery)
During beforeBuild, if <cache_dir>/translations/.config.json exists, it is merged into config('locales'). This
makes newly generated languages available without editing project config.
Example .config.json (generated):
{
"en": {
"name": "English"
},
"ru": {
"name": "Русский"
}
}
Place this file at temp/translations/.config.json if cache_dir is temp/ and main points to the project root.
Path resolution & tips
- Prefer absolute paths in config (
__DIR__) to avoid CWD issues. - Keep trailing slashes consistent (as in the example) to avoid duplicate separators when concatenating.
- If you change
cache_dir, update the Docara bootstrap path which reads.config.json.
Multi-locale examples
EN → RU, DE
return [
'target_lang' => 'en',
'languages' => ['ru','de'],
'frontMatter' => ['title','description','summary'],
// other keys as above
];
RU → EN (base locale is Russian)
return [
'target_lang' => 'ru',
'languages' => ['en'],
'source_dir' => __DIR__ . '/source/',
'output_dir' => __DIR__ . '/source',
'cache_dir' => 'temp/',
];
Validation checklist
source_direxists and contains_docs-<target_lang>.output_diris writable (or identical tosource_dir).languagesis non-empty and does not includetarget_lang..envhas valid Azure credentials.- Docara
beforeBuildreads<cache_dir>/translations/.config.json.
Common mistakes
- Mismatched cache path: you configured
cache_dirbut bootstrap still readstemp/translations/.config.json. Fix the bootstrap path or setcache_dirback totemp/. - Confusing
target_lang: remember this is the source language. Targets go intolanguages. - Relative paths + CWD: use absolute paths with
__DIR__to avoid surprises when running from CI.