48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
// scripts/generate-docs.php
|
|
|
|
class DocumentationGenerator
|
|
{
|
|
private array $languages = [
|
|
'de' => 'Deutsch',
|
|
'fr' => 'Français',
|
|
'es' => 'Español',
|
|
'it' => 'Italiano',
|
|
'ja' => '日本語',
|
|
'zh' => '中文'
|
|
];
|
|
|
|
public function generateAllLanguages(): void
|
|
{
|
|
$baseTemplate = file_get_contents(__DIR__ . '/../docs/index.html');
|
|
|
|
foreach ($this->languages as $code => $name) {
|
|
$translated = $this->translateContent($baseTemplate, $code);
|
|
file_put_contents(__DIR__ . "/../docs/docs-{$code}.html", $translated);
|
|
echo "Generated docs-{$code}.html\n";
|
|
}
|
|
}
|
|
|
|
private function translateContent(string $content, string $lang): string
|
|
{
|
|
// Load translations from JSON files
|
|
$translations = json_decode(
|
|
file_get_contents(__DIR__ . "/../locales/{$lang}.json"),
|
|
true
|
|
);
|
|
|
|
// Replace content with translations
|
|
$content = str_replace('lang="en"', "lang=\"{$lang}\"", $content);
|
|
|
|
// Replace specific content sections
|
|
foreach ($translations as $key => $value) {
|
|
$content = str_replace("{{$key}}", $value, $content);
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
}
|
|
|
|
// Usage
|
|
$generator = new DocumentationGenerator();
|
|
$generator->generateAllLanguages(); |