From a9684792106e4de3aa622d33a0ed7780cbd67ad0 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Fri, 11 Aug 2017 03:24:07 +0200 Subject: Several changes have been made in this commit, which together with the previous commits result in version 2.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 --- core/namespace/Application.php | 4 +- core/namespace/Language.php | 64 +++++++++++++++++--------------- template/admin/html/403.php | 4 +- template/admin/html/404.php | 4 +- template/admin/html/auth.php | 10 ++--- template/admin/html/database.php | 6 +-- template/admin/html/home.php | 16 ++++---- template/admin/html/main.php | 8 ++-- template/admin/html/page/delete.php | 2 +- template/admin/html/page/form.php | 30 +++++++-------- template/admin/html/page/index.php | 2 +- template/admin/html/page/insert.php | 2 +- template/admin/html/page/item.php | 2 +- template/admin/html/page/update.php | 2 +- template/admin/html/post/delete.php | 2 +- template/admin/html/post/form.php | 30 +++++++-------- template/admin/html/post/index.php | 2 +- template/admin/html/post/insert.php | 2 +- template/admin/html/post/item.php | 2 +- template/admin/html/post/update.php | 2 +- template/admin/html/user/delete.php | 4 +- template/admin/html/user/form.php | 34 ++++++++--------- template/admin/html/user/index.php | 2 +- template/admin/html/user/insert.php | 2 +- template/admin/html/user/item.php | 2 +- template/admin/html/user/update.php | 2 +- template/admin/lang/de.php | 2 +- template/admin/lang/en.php | 2 +- template/standard/html/403.php | 4 +- template/standard/html/404.php | 4 +- template/standard/html/home.php | 4 +- template/standard/html/main.php | 8 ++-- template/standard/html/page/item.php | 2 +- template/standard/html/page/list.php | 2 +- template/standard/html/page/main.php | 4 +- template/standard/html/post/item.php | 2 +- template/standard/html/post/list.php | 2 +- template/standard/html/post/main.php | 4 +- template/standard/html/search/main.php | 6 +-- template/standard/html/search/result.php | 6 +-- template/standard/html/user/list.php | 2 +- template/standard/html/user/main.php | 2 +- template/standard/lang/de.php | 2 +- template/standard/lang/en.php | 2 +- 44 files changed, 154 insertions(+), 148 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 @@ 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 diff --git a/template/admin/html/403.php b/template/admin/html/403.php index aebddb7..f9a0afd 100644 --- a/template/admin/html/403.php +++ b/template/admin/html/403.php @@ -1,2 +1,2 @@ -

template('403_heading_text')?>

-

template('403_heading_desc')?>

+

text('403_heading_text')?>

+

text('403_heading_desc')?>

diff --git a/template/admin/html/404.php b/template/admin/html/404.php index 4f841b6..aa264cd 100644 --- a/template/admin/html/404.php +++ b/template/admin/html/404.php @@ -1,2 +1,2 @@ -

template('404_heading_text')?>

-

template('404_heading_desc')?>

\ No newline at end of file +

text('404_heading_text')?>

+

text('404_heading_desc')?>

\ No newline at end of file diff --git a/template/admin/html/auth.php b/template/admin/html/auth.php index 186c096..6aec620 100644 --- a/template/admin/html/auth.php +++ b/template/admin/html/auth.php @@ -1,5 +1,5 @@ -

template('authentication_text')?>

-

template('authentication_desc')?>

+

text('authentication_text')?>

+

text('authentication_desc')?>

@@ -17,18 +17,18 @@
-
+
-
+
- +
\ No newline at end of file diff --git a/template/admin/html/database.php b/template/admin/html/database.php index 319bf02..983dee7 100644 --- a/template/admin/html/database.php +++ b/template/admin/html/database.php @@ -1,5 +1,5 @@ -

template('overview_database_text')?>

-

template('overview_database_desc')?>

+

text('overview_database_text')?>

+

text('overview_database_desc')?>

@@ -15,7 +15,7 @@
- +
diff --git a/template/admin/html/home.php b/template/admin/html/home.php index 6701f35..6ade82d 100644 --- a/template/admin/html/home.php +++ b/template/admin/html/home.php @@ -1,17 +1,17 @@ -

template('overview_dashboard_text')?>

-

template('overview_dashboard_desc')?>

+

text('overview_dashboard_text')?>

+

text('overview_dashboard_desc')?>

-

template('last_post')?>

+

text('last_post')?>

text('posts')?>: | text('post_overview')?> | text('insert')?>

-

template('home_no_posts')?>

+

text('home_no_posts')?>

-

template('last_page')?>

+

text('last_page')?>

text('pages')?>: | text('page_overview')?> | text('insert')?>

@@ -19,10 +19,10 @@ -

template('home_no_pages')?>

+

text('home_no_pages')?>

-

template('last_user')?>

+

text('last_user')?>

text('users')?>: | text('user_overview')?> | text('insert')?>

@@ -30,5 +30,5 @@ -

template('home_no_users')?>

+

text('home_no_users')?>

diff --git a/template/admin/html/main.php b/template/admin/html/main.php index d7b6148..fafc8d0 100644 --- a/template/admin/html/main.php +++ b/template/admin/html/main.php @@ -22,18 +22,18 @@ diff --git a/template/admin/html/page/delete.php b/template/admin/html/page/delete.php index 95451d8..ccc569f 100644 --- a/template/admin/html/page/delete.php +++ b/template/admin/html/page/delete.php @@ -1,4 +1,4 @@

text('delete_page')?>

-

template('delete_page_desc')?>

+

text('delete_page_desc')?>

\ No newline at end of file diff --git a/template/admin/html/page/form.php b/template/admin/html/page/form.php index c0bc7e4..ad7387f 100644 --- a/template/admin/html/page/form.php +++ b/template/admin/html/page/form.php @@ -20,7 +20,7 @@
-
+
-
+
-
+
-
+
    -
  • -
  • -
  • - -
  • -
  • -
  • -
  • -
  • +
  • +
  • +
  • + +
  • +
  • +
  • +
  • +
@@ -92,7 +92,7 @@ - +
\ No newline at end of file diff --git a/template/admin/html/page/index.php b/template/admin/html/page/index.php index 8fff434..0989796 100644 --- a/template/admin/html/page/index.php +++ b/template/admin/html/page/index.php @@ -1,5 +1,5 @@

text('page_overview')?>">text('insert')?>

-

template('overview_page_desc')?>

+

text('overview_page_desc')?>