* multi-language support.

This commit is contained in:
larukedi 2013-08-23 22:49:08 +03:00
parent f540c54482
commit ca377311e9
2 changed files with 52 additions and 22 deletions

View File

@ -66,11 +66,26 @@ software, even if advised of the possibility of such damage.
require_once('libs/functions.php'); require_once('libs/functions.php');
$options = get_options(); $options = get_options();
$tree = get_tree("docs", $base_url); $url_params = url_params();
$homepage_url = homepage_url($tree);
$docs_url = docs_url($tree);
$page = load_page($tree); if (count($options['languages']) > 0 && count($url_params) > 0 && strlen($url_params[0]) > 0) {
$language = array_shift($url_params);
$base_path = "docs/" . $language;
} else {
$language = null;
$base_path = "docs";
}
$tree = get_tree($base_path, $base_url, '', true, $language);
if ($language === null) {
$homepage_url = homepage_url($tree);
$docs_url = docs_url($tree);
} else {
$homepage_url = "/";
}
$page = load_page($tree, $url_params);
// If a timezone has been set in the config file, override the default PHP timezone for this application. // If a timezone has been set in the config file, override the default PHP timezone for this application.
if(isset($options['timezone'])) if(isset($options['timezone']))
@ -138,7 +153,7 @@ if ($homepage && $homepage_url !== '/') {
<div class="navbar navbar-fixed-top"> <div class="navbar navbar-fixed-top">
<div class="navbar-inner"> <div class="navbar-inner">
<div class="container"> <div class="container">
<a class="brand pull-left" href="<?php echo $base_url ?>/<?php echo $homepage_url;?>"><?php echo $options['title']; ?></a> <a class="brand pull-left" href="<?php echo $base_url ?><?php echo $homepage_url;?>"><?php echo $options['title']; ?></a>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
Generated by <a href="http://daux.io">Daux.io</a> Generated by <a href="http://daux.io">Daux.io</a>
</p> </p>
@ -174,9 +189,17 @@ if ($homepage && $homepage_url !== '/') {
View On GitHub View On GitHub
</a> </a>
<?php } ?> <?php } ?>
<?php if (count($options['languages']) > 0) { ?>
<?php foreach ($options['languages'] as $language_key => $language_name) { ?>
<a href="<?php echo $base_url . "/" . $language_key . "/"; ?>" class="btn btn-primary btn-hero">
<?php echo $language_name; ?>
</a>
<?php } ?>
<?php } else { ?>
<a href="<?php echo $docs_url;?>" class="btn btn-primary btn-hero"> <a href="<?php echo $docs_url;?>" class="btn btn-primary btn-hero">
View Documentation View Documentation
</a> </a>
<?php } ?>
</div> </div>
</div> </div>
</div> </div>
@ -246,7 +269,7 @@ if ($homepage && $homepage_url !== '/') {
</div> </div>
<div id="sub-nav-collapse" class="sub-nav-collapse"> <div id="sub-nav-collapse" class="sub-nav-collapse">
<!-- Navigation --> <!-- Navigation -->
<?php echo build_nav($tree); ?> <?php echo build_nav($tree, $url_params); ?>
<?php if (!empty($options['links']) || !empty($options['twitter'])) { ?> <?php if (!empty($options['links']) || !empty($options['twitter'])) { ?>
<div class="well well-sidebar"> <div class="well well-sidebar">

View File

@ -44,7 +44,8 @@ function get_options() {
'clean_urls' => true, 'clean_urls' => true,
'google_analytics' => false, 'google_analytics' => false,
'piwik_analytics' => false, 'piwik_analytics' => false,
'ignore' => array() 'ignore' => array(),
'languages' => array()
); );
// Load User Config // Load User Config
@ -75,7 +76,7 @@ function homepage_url($tree) {
if (isset($tree['index'])) { if (isset($tree['index'])) {
return '/'; return '/';
} else { } else {
return docs_url($tree); return docs_url($tree, false);
} }
} }
@ -101,8 +102,12 @@ function docs_url($tree, $branch = false) {
} }
} }
function load_page($tree) { function load_page($tree, $url_params) {
$branch = find_branch($tree); if (count($url_params) > 0) {
$branch = find_branch($tree, $url_params);
} else {
$branch = current($tree);
}
$page = array(); $page = array();
@ -129,9 +134,8 @@ function load_page($tree) {
return $page; return $page;
} }
function find_branch($tree) { function find_branch($tree, $url_params) {
$path = url_params(); foreach($url_params as $peice) {
foreach($path as $peice) {
// Check for homepage // Check for homepage
if (empty($peice)) { if (empty($peice)) {
$peice = 'index'; $peice = 'index';
@ -182,13 +186,10 @@ function clean_name($text) {
return $text; return $text;
} }
function build_nav($tree, $url_params = false) { function build_nav($tree, $url_params) {
// Remove Index // Remove Index
unset($tree['index']); unset($tree['index']);
if (!is_array($url_params)) {
$url_params = url_params();
}
$url_path = url_path(); $url_path = url_path();
$html = '<ul class="nav nav-list">'; $html = '<ul class="nav nav-list">';
foreach($tree as $key => $val) { foreach($tree as $key => $val) {
@ -244,7 +245,7 @@ function get_ignored() {
return $all_ignored; return $all_ignored;
} }
function get_tree($path = '.', $clean_path = '', $title = '', $first = true){ function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $language = null){
$options = get_options(); $options = get_options();
$tree = array(); $tree = array();
$ignore = get_ignored(); $ignore = get_ignored();
@ -262,6 +263,12 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
// Sort paths // Sort paths
sort($paths); sort($paths);
if ($first && $language !== null) {
$language_path = $language . "/";
} else {
$language_path = "";
}
// Loop through the paths // Loop through the paths
// while(false !== ($file = readdir($dh))){ // while(false !== ($file = readdir($dh))){
@ -277,16 +284,16 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
{ {
if($first) if($first)
{ {
$url = $clean_path . '/index.php/' . $clean_sort; $url = $clean_path . '/' . $language_path . 'index.php/' . $clean_sort;
} }
else else
{ {
$url = $clean_path . '/' . $clean_sort; $url = $clean_path . '/' . $language_path . $clean_sort;
} }
} }
else else
{ {
$url = $clean_path . '/' . $clean_sort; $url = $clean_path . '/' . $language_path . $clean_sort;
} }
$clean_name = clean_name($clean_sort); $clean_name = clean_name($clean_sort);
@ -307,7 +314,7 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
'path' => $full_path, 'path' => $full_path,
'clean' => $clean_sort, 'clean' => $clean_sort,
'url' => $url, 'url' => $url,
'tree'=> get_tree($full_path, $url, $full_title, false) 'tree'=> get_tree($full_path, $url, $full_title, false, $language)
); );
} else { } else {
// File // File