mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-08-06 05:07:49 +02:00
Monstra MultiLanguage Development Init Commit
This commit is contained in:
@@ -224,7 +224,11 @@ class Monstra
|
||||
/**
|
||||
* Init I18n
|
||||
*/
|
||||
I18n::init(Option::get('language'));
|
||||
if (BACKEND) {
|
||||
I18n::init('admin', Option::get('language'));
|
||||
} else {
|
||||
I18n::init('site', Site::getCurrentSiteLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Plugins API
|
||||
@@ -235,7 +239,7 @@ class Monstra
|
||||
* Init Notification service
|
||||
*/
|
||||
Notification::init();
|
||||
|
||||
|
||||
/**
|
||||
* Init site module
|
||||
*/
|
||||
@@ -315,6 +319,7 @@ class Monstra
|
||||
if (count($namespaces = Dir::scan(CACHE)) > 0) foreach ($namespaces as $namespace) Dir::delete(CACHE . DS . $namespace);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize Monstra Engine
|
||||
*
|
||||
|
@@ -75,9 +75,9 @@ class I18n
|
||||
*
|
||||
* @param string $dir Plugins directory
|
||||
*/
|
||||
public static function init($locale)
|
||||
public static function init($namespace = 'default', $locale)
|
||||
{
|
||||
if ( ! isset(self::$instance)) self::$instance = new I18n($locale);
|
||||
if ( ! isset(self::$instance)) self::$instance = new I18n($namespace, $locale);
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ class I18n
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
protected function __construct($locale)
|
||||
protected function __construct($namespace = 'default', $locale)
|
||||
{
|
||||
// Redefine arguments
|
||||
$locale = (string) $locale;
|
||||
|
||||
// Get lang table for current locale
|
||||
$lang_table = Cache::get('i18n', $locale);
|
||||
$lang_table = Cache::get('i18n_'.$namespace, $locale);
|
||||
|
||||
// If lang_table is empty then create new
|
||||
if (! $lang_table) {
|
||||
@@ -136,7 +136,7 @@ class I18n
|
||||
}
|
||||
|
||||
// Save lang table for current locale
|
||||
Cache::put('i18n', $locale, $lang_table);
|
||||
Cache::put('i18n_'.$namespace, $locale, $lang_table);
|
||||
|
||||
// Update dictionary
|
||||
I18n::$dictionary = $lang_table;
|
||||
|
@@ -221,4 +221,38 @@ class Site
|
||||
return __('Powered by', 'system').' <a href="http://monstra.org" target="_blank">Monstra</a> ' . Monstra::VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function getLocales() {
|
||||
$language_files = File::scan(PLUGINS_BOX . DS . 'system' . DS . 'languages' . DS, '.lang.php');
|
||||
foreach ($language_files as $language) {
|
||||
$parts = explode('.', $language);
|
||||
$languages_array[$parts[0]] = I18n::$locales[$parts[0]];
|
||||
}
|
||||
return $languages_array;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function getDefaultSiteLocale() {
|
||||
return Option::get('site_language');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function getCurrentSiteLocale() {
|
||||
$site_locales = Site::getLocales();
|
||||
|
||||
|
||||
if (Uri::segment(0) && array_key_exists(Uri::segment(0), $site_locales)) {
|
||||
return Uri::segment(0);
|
||||
} else {
|
||||
$site_locale = Cookie::get('site_locale');
|
||||
return !empty($site_locale) ? $site_locale : Option::get('site_language');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user