Olodoc supports English, Turkish and German languages by default. If you want Olodoc to support more languages, you can contribute by adding the languages you know to Olodoc from our github repo address.
//github.com/olomadev/olodoc-skeleton/blob/main/data/language/en/olodoc.php
In your application, only 1 file named default.php needs to be translated to your languages. The other one is the core translation file olodoc.php. If your languages are not in the language directory, it needs to be copied and translated.
data/language/en/default.php
(your app translations)data/language/en/olodoc.php
(olodoc translations)- myproject
+ bin
+ config
- data
- language
- en
default.php
olodoc.php
- tr
default.php
olodoc.php
To add language support to your navigation index file, all you need to do is use the $translator->translate() object method as in the example below for your existing tags in this file.
The translate object here is the
Laminas\I18n\Translator\Translator
class that was included in your application with theOlodoc/LaminasDocumentManagerFactory
.
<?php
/**
* Navigation index
*/
return [
[
'label' => $translator->translate('Introduction'),
'url' => '/index.html',
'meta' => [
'title' => $translator->translate('Introduction'),
'keywords' => $translator->translate('intro, introduction, open source, document, generation, php'),
'description' => $translator->translate('Olodoc is an open source documentation creation tool developed in PHP to create documentation from your foldered markdown files. It allows you to create and customize unique templates for your applications with the Bootstrap 5 CSS framework'),
]
],
[
'label' => $translator->translate('Installation'),
'url' => '/installation.html',
],
];
If you are setting up a multilingual project via a subdomain, add the languages you plan to support as follows.
127.0.1.1 example.local
127.0.1.1 en.example.local
127.0.1.1 tr.example.local
Now you can visit yout application with your new language.
http://tr.example.local
For example to add German (de) language we need to follow below the steps.
return [
//
// olodoc
//
'olodoc' => [
/** .... */
'default_locale' => 'en',
'available_locales' => [
'en' => 'English',
'tr' => 'Türkçe',
'de' => 'German',
],
];
];
?>
return [
//
// olodoc
//
'olodoc' => [
/** .... */
'anchors_for_index_pages' => true, // if false anchors will not be created in index.html routes
//
// More flags is here: https://github.com/lipis/flag-icons/tree/main/flags/1x1
//
'flags' => [
'en' => '<svg xmlns="http://www.w3.org/2000/svg" class="grayscale" width="24" height="24" id="flag-icons-en" style="border-radius: 50%;" viewBox="0 0 512 512"><path fill="#bd3d44" d="M0 0h512v512H0"/><path stroke="#fff" stroke-width="40" d="M0 58h512M0 137h512M0 216h512M0 295h512M0 374h512M0 453h512"/><path fill="#192f5d" d="M0 0h390v275H0z"/><marker id="us-a" markerHeight="30" markerWidth="30"><path fill="#fff" d="m15 0 9.3 28.6L0 11h30L5.7 28.6"/></marker><path fill="none" marker-mid="url(#us-a)" d="m0 0 18 11h65 65 65 65 66L51 39h65 65 65 65L18 66h65 65 65 65 66L51 94h65 65 65 65L18 121h65 65 65 65 66L51 149h65 65 65 65L18 177h65 65 65 65 66L51 205h65 65 65 65L18 232h65 65 65 65 66z"/></svg>',
'tr' => '<svg xmlns="http://www.w3.org/2000/svg" class="grayscale" width="24" height="24" id="flag-icons-tr" style="border-radius: 50%;" viewBox="0 0 512 512"><g fill-rule="evenodd"><path fill="#e30a17" d="M0 0h512v512H0z"/><path fill="#fff" d="M348.8 264c0 70.6-58.3 127.9-130.1 127.9s-130.1-57.3-130.1-128 58.2-127.8 130-127.8S348.9 193.3 348.9 264z"/><path fill="#e30a17" d="M355.3 264c0 56.5-46.6 102.3-104.1 102.3s-104-45.8-104-102.3 46.5-102.3 104-102.3 104 45.8 104 102.3z"/><path fill="#fff" d="m374.1 204.2-1 47.3-44.2 12 43.5 15.5-1 43.3 28.3-33.8 42.9 14.8-24.8-36.3 30.2-36.1-46.4 12.8z"/></g></svg>',
'de' => '<svg xmlns="http://www.w3.org/2000/svg" class="grayscale" id="flag-icons-de" viewBox="0 0 512 512"><path fill="#fc0" d="M0 341.3h512V512H0z"/><path fill="#000001" d="M0 0h512v170.7H0z"/><path fill="red" d="M0 170.7h512v170.6H0z"/></svg>',
],
],
];
'flags' => [
'de' => '<svg xmlns="http://www.w3.org/2000/svg"
class="grayscale ol-flag" id="flag-icons-de" viewBox="0 0 512 512">
<path fill="#fc0" d="M0 341.3h512V512H0z"/>
<path fill="#000001" d="M0 0h512v170.7H0z"/>
<path fill="red" d="M0 170.7h512v170.6H0z"/>
</svg>'
];
Copy default.php and olodoc.php language files then translate them into to German language.
- myproject
+ bin
+ config
- data
- language
- en
default.php
olodoc.php
+ tr
- de
default.php
olodoc.php
- myproject
+ bin
+ config
- data
- docs
- 1.0
- en
index.md
installation.md
+ tr
- de
index.md
installation.md
127.0.1.1 example.local
127.0.1.1 en.example.local
127.0.1.1 tr.example.local
127.0.1.1 de.example.local
and make sure you have a alias configuration in your apache vhost file like below.
<VirtualHost *:80>
SetEnv "APP_ENV" "local"
ServerName example.local
ServerAlias *.example.local # subdomain support
ServerAdmin webmaster@localhost
DocumentRoot /var/www/myproject/public/
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now you can generate your new german documents using command line to html files.
composer olodoc:generate
Visit the en.example.local adress from your browser if everyting went well you will see your new language in your navigation bar like below.