aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-08-11 03:24:07 +0200
committerThomas Lange <code@nerdmind.de>2017-08-11 03:24:07 +0200
commita9684792106e4de3aa622d33a0ed7780cbd67ad0 (patch)
tree4051a0a99e2b4388bd919d3c90444d6b612a0400 /core/namespace
parent6c550895ef0f27bf84b8a5d7917eeee3e3122f67 (diff)
downloadblog-a9684792106e4de3aa622d33a0ed7780cbd67ad0.tar.gz
blog-a9684792106e4de3aa622d33a0ed7780cbd67ad0.tar.xz
blog-a9684792106e4de3aa622d33a0ed7780cbd67ad0.zip
Several changes have been made in this commit, which together with the previous commits result in version 2.3:v2.3
+ Optimization: Originally, the core and template languages were completely separated in the logic of the Language class and you had to use "$Language->text()" to get a core language string and "$Language->template()" to get a template language string. Since this commit, the core and template language strings are still located in different files, but you now have to use "$Language->text()" for core and template language strings both. Thus, you can now even overwrite a core language string from the language file of a template if the core language string does not satisfy you. + Deprecated: The method "$Language->template()" was marked as deprecated and will be removed in further versions (currently, it's just an alias for "$Language->text()"). Template upgrade to version 2.3 (only for customized templates): SEARCH: $Language->template REPLACE: $Language->text
Diffstat (limited to 'core/namespace')
-rw-r--r--core/namespace/Application.php4
-rw-r--r--core/namespace/Language.php64
2 files changed, 37 insertions, 31 deletions
diff --git a/core/namespace/Application.php b/core/namespace/Application.php
index 4fa80cc..4a6414a 100644
--- a/core/namespace/Application.php
+++ b/core/namespace/Application.php
@@ -58,7 +58,9 @@ class Application {
$template_lang = self::get('TEMPLATE.LANG');
$Language = new Language(self::get('CORE.LANGUAGE'));
- $Language->loadLanguage(sprintf(ROOT.'template/%s/lang/%s.php', $template_name, $template_lang));
+ $Language->load(sprintf(ROOT.'core/language/%s.php', Application::get('CORE.LANGUAGE')));
+ $Language->load(sprintf(ROOT.'template/%s/lang/%s.php', $template_name, $template_lang));
+
self::$Language = $Language;
}
diff --git a/core/namespace/Language.php b/core/namespace/Language.php
index c8a018e..fdaf104 100644
--- a/core/namespace/Language.php
+++ b/core/namespace/Language.php
@@ -1,48 +1,52 @@
<?php
class Language {
- private $language = [];
- private $template = [];
+ private $code = '';
+ private $text = [];
- public function __construct($lang) {
- require ROOT."core/language/{$lang}.php";
- $this->language = $LANGUAGE;
+ public function __construct($code) {
+ $this->code = $code;
}
- public function loadLanguage($filename) {
- require $filename;
- $this->template = $LANGUAGE;
+ #===============================================================================
+ # Return the language code
+ #===============================================================================
+ public function getCode() {
+ return $this->code;
}
- public function template($name, $params = FALSE) {
- if(isset($this->template[$name])) {
- if($params) {
- return vsprintf($this->template[$name], $params);
- }
-
- return $this->template[$name];
+ #===============================================================================
+ # Load another language file
+ #===============================================================================
+ public function load($filename) {
+ if(file_exists($filename) AND is_readable($filename)) {
+ require $filename;
+ $this->text = array_merge($this->text, $LANGUAGE ?? []);
}
-
- return "{{$name}}";
}
- private function get($name, $params = FALSE) {
- if(isset($this->language[$name])) {
- if($params) {
- return vsprintf($this->language[$name], $params);
- }
+ #===============================================================================
+ # Set language string
+ #===============================================================================
+ public function set($name, $value) {
+ return $this->text[$name] = $value;
+ }
- return $this->language[$name];
+ #===============================================================================
+ # Return language string with included arguments
+ #===============================================================================
+ public function text($name, $arguments = NULL): string {
+ if(!isset($this->text[$name])) {
+ return "{{$name}}";
}
- return "{{$name}}";
+ return vsprintf($this->text[$name], $arguments);
}
- public function text($name, $params = FALSE) {
- return $this->get($name, $params);
- }
-
- public function set($name, $value) {
- return $this->language[$name] = $value;
+ #===============================================================================
+ # DEPRECATED: This method will be removed in the future!
+ #===============================================================================
+ public function template($name, $params = FALSE): string {
+ return $this->text($name, $params);
}
}
?> \ No newline at end of file