some initial lang work

This commit is contained in:
Andy Miller
2015-06-26 12:25:22 -06:00
parent ea491fbde5
commit 917a5c3082
6 changed files with 92 additions and 9 deletions

View File

@@ -5,6 +5,10 @@ param_sep: ':' # Parameter separator, use ';' for Apache
home:
alias: '/home' # Default path for home, ie /
languages:
en: English
fr: French
pages:
theme: antimatter # Default theme (defaults to "antimatter" theme)
order:
@@ -32,7 +36,7 @@ pages:
'<': 'lt'
types: 'txt|xml|html|json|rss|atom' # Pipe separated list of valid page types
expires: 0 # Page expires time in seconds (604800 seconds = 7 days)
last_modified: false # Set the last modified date header based on file modification timestamp
last_modified: false # Set the last modified date header based on file modifcation timestamp
etag: false # Set the etag header tag
cache:
@@ -79,7 +83,7 @@ images:
debug: false # Show an overlay over images indicating the pixel depth of the image when working with retina for example
media:
enable_media_timestamp: false # Enable media timestamps
enable_media_timestamp: false # Enable media timetsamps
upload_limit: 0 # Set maximum upload size in bytes (0 is unlimited)
security:

View File

@@ -38,12 +38,12 @@ abstract class Folder
* Recursively find the last modified time under given path by file.
*
* @param string $path
* @param string $extensions
*
* @return int
*/
public static function lastModifiedFile($path)
public static function lastModifiedFile($path, $extensions = 'md|yaml')
{
// pipe separated list of extensions to search for changes with
$extensions = 'md|yaml';
$last_modified = 0;
$dirItr = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);

View File

@@ -55,6 +55,8 @@ class Grav extends Container
$container['grav'] = $container;
$container['debugger'] = new Debugger();
$container['debugger']->startTimer('_init', 'Initialize');
@@ -88,12 +90,16 @@ class Grav extends Container
$container['taxonomy'] = function ($c) {
return new Taxonomy($c);
};
$container['language'] = function ($c) {
return new Language($c);
};
$container['pages'] = function ($c) {
return new Page\Pages($c);
};
$container['assets'] = function ($c) {
return new Assets();
};
$container['assets'] = new Assets();
$container['page'] = function ($c) {
/** @var Pages $pages */
$pages = $c['pages'];

View File

@@ -0,0 +1,58 @@
<?php
namespace Grav\Common;
/**
* Contain some useful language functions
*/
class Language
{
protected $languages = [];
protected $default_key;
protected $default_lang;
protected $active_key;
protected $active_lang;
public function __construct(Grav $grav)
{
$this->languages = $grav['config']->get('system.languages', []);
$this->default_key = key($this->languages);
$this->default_lang = reset($this->languages);
}
public function setLanguage($key)
{
if (array_key_exists($key, $this->languages)) {
$this->active_key = $key;
$this->active_lang = $this->languages[$key];
return true;
}
return false;
}
public function getAvailableKeys()
{
return implode('|', array_keys($this->languages));
}
public function getDefaultKey()
{
return $this->default_key;
}
public function getDefaultLanguage()
{
return $this->default_lang;
}
public function getActiveKey()
{
return $this->active_key;
}
public function getActiveLanguage()
{
return $this->active_lang;
}
}

View File

@@ -6,6 +6,7 @@ use Grav\Common\Config\Config;
use Grav\Common\Utils;
use Grav\Common\Cache;
use Grav\Common\Taxonomy;
use Grav\Common\Language;
use Grav\Common\Data\Blueprint;
use Grav\Common\Data\Blueprints;
use Grav\Common\Filesystem\Folder;
@@ -61,6 +62,10 @@ class Pages
*/
protected $last_modified;
protected $default_lang;
protected $page_extension;
/**
* @var Types
*/
@@ -75,6 +80,8 @@ class Pages
{
$this->grav = $c;
$this->base = '';
$this->default_lang = $c['language']->getDefaultKey();
$this->page_extension = '.' . $this->default_lang ? $this->default_lang . CONTENT_EXT : CONTENT_EXT;
}
/**
@@ -572,7 +579,7 @@ class Pages
$last_modified = $modified;
}
if (preg_match('/^[^.].*'.CONTENT_EXT.'$/', $name)) {
if (preg_match('/^[^.].*'.$this->page_extension.'$/', $name)) {
$page->init($file);
$content_exists = true;

View File

@@ -73,6 +73,7 @@ class Uri
public function init()
{
$config = Grav::instance()['config'];
$language = Grav::instance()['language'];
// resets
$this->paths = [];
@@ -86,6 +87,13 @@ class Uri
// process params
$uri = $this->processParams($uri, $config->get('system.param_sep'));
$regex = '/(\/(?:'.$language->getAvailablekeys().')\/).*/';
if (preg_match($regex, $uri, $matches)) {
$uri = preg_replace("/\\".$matches[1]."/", '', $matches[0], 1);
$lang = $matches[2];
}
// split the URL and params
$bits = parse_url($uri);