From 0dd2d04c91775c8ccf1da914e0a0891de8d5e887 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Ke=C3=9Fler?= Date: Fri, 18 Nov 2022 12:59:48 +0100 Subject: [PATCH] i18n now available --- CHANGELOG | 3 +- documentation/i18n.txt | 6 +++ documentation/upgrade-from-1.0.txt | 6 +++ webroot/config/config.php.default | 3 ++ webroot/index.php | 4 ++ webroot/lib/i18n.class.php | 64 ++++++++++++++++++++++++++++++ webroot/lib/i18n/de.ini | 13 ++++++ webroot/lib/i18n/en.ini | 23 +++++++++++ webroot/view/entry/entry.html | 8 ++-- webroot/view/list/list.html | 6 +-- 10 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 documentation/i18n.txt create mode 100644 documentation/upgrade-from-1.0.txt create mode 100644 webroot/lib/i18n.class.php create mode 100644 webroot/lib/i18n/de.ini create mode 100644 webroot/lib/i18n/en.ini diff --git a/CHANGELOG b/CHANGELOG index 49d59ef..7204f1c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ 1.x Atlas - + + i18n. See upgrade-from-1.0.txt for more details. 1.0 Lykos - 2022-11-12 - - Initial release + + Initial release diff --git a/documentation/i18n.txt b/documentation/i18n.txt new file mode 100644 index 0000000..9ae216e --- /dev/null +++ b/documentation/i18n.txt @@ -0,0 +1,6 @@ +Other languages are supported by the i18n ini files in the lib/i18n folder. +It uses the two char lang code as a filename. + +To add a new translation copy the existing en.ini file and rename it to the new language. +Edit every value for each key in the file. Get in touch or even make a PR via github to +get the new language added. \ No newline at end of file diff --git a/documentation/upgrade-from-1.0.txt b/documentation/upgrade-from-1.0.txt new file mode 100644 index 0000000..f9783b8 --- /dev/null +++ b/documentation/upgrade-from-1.0.txt @@ -0,0 +1,6 @@ +New config for i18n. Open config.php and add the following: + +# language settings +const FRONTEND_LANGUAGE = 'en'; + +currently only en (default) and de are available. \ No newline at end of file diff --git a/webroot/config/config.php.default b/webroot/config/config.php.default index 7098d44..330c474 100644 --- a/webroot/config/config.php.default +++ b/webroot/config/config.php.default @@ -23,6 +23,9 @@ const QUERY_DEBUG = true; # timezone settings const TIMEZONE = 'Europe/Berlin'; +# language settings +const FRONTEND_LANGUAGE = 'en'; + # path settings const PATH_ABSOLUTE = '/home/banana/code/scientia/webroot'; const PATH_SYSTEMOUT = PATH_ABSOLUTE . '/systemout'; diff --git a/webroot/index.php b/webroot/index.php index e8aa27e..d29d968 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -46,9 +46,13 @@ date_default_timezone_set(TIMEZONE); # required libs require_once('lib/summoner.class.php'); +require_once('lib/i18n.class.php'); Summoner::simpleAuth(); +# i18n +$i18n = new I18n(); + # database object $DB = false; diff --git a/webroot/lib/i18n.class.php b/webroot/lib/i18n.class.php new file mode 100644 index 0000000..6ded228 --- /dev/null +++ b/webroot/lib/i18n.class.php @@ -0,0 +1,64 @@ +_defaultLangToUse.'.ini'; + if(defined('FRONTEND_LANGUAGE')) { + $_langFile = ABSOLUTE_PATH.'/lib/i18n/'.FRONTEND_LANGUAGE.'.ini'; + if(file_exists($_langFile)) { + $_langData = parse_ini_file($_langFile); + if($_langData !== false) { + $this->_langData = $_langData; + } + } + } + else { + $_langData = parse_ini_file($_langFile); + if($_langData !== false) { + $this->_langData = $_langData; + } + } + } + + /** + * Return text for given key for currently loaded lang + * + * @param string $key + * @return string + */ + public function t(string $key): string { + $ret = $key; + if(isset($this->_langData[$key])) { + $ret = $this->_langData[$key]; + } + return $ret; + } +} \ No newline at end of file diff --git a/webroot/lib/i18n/de.ini b/webroot/lib/i18n/de.ini new file mode 100644 index 0000000..6de9792 --- /dev/null +++ b/webroot/lib/i18n/de.ini @@ -0,0 +1,13 @@ +; scientia +; +; Copyright 2022 Johannes Keßler +; +; https://www.bananas-playground.net/projekt/scientia/ +; +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE +; +; You should have received a copy of the +; COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +; along with this program. If not, see http://www.sun.com/cddl/cddl.html diff --git a/webroot/lib/i18n/en.ini b/webroot/lib/i18n/en.ini new file mode 100644 index 0000000..55cb0f8 --- /dev/null +++ b/webroot/lib/i18n/en.ini @@ -0,0 +1,23 @@ +; scientia +; +; Copyright 2022 Johannes Keßler +; +; https://www.bananas-playground.net/projekt/scientia/ +; +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE +; +; You should have received a copy of the +; COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +; along with this program. If not, see http://www.sun.com/cddl/cddl.html + +form.button.save=Save +form.button.search=Search +form.checkbox.deleteentry=Delete Entry + + +text.new=New +text.home=Home +text.noentries=Nothing here. + diff --git a/webroot/view/entry/entry.html b/webroot/view/entry/entry.html index 021e146..a480212 100644 --- a/webroot/view/entry/entry.html +++ b/webroot/view/entry/entry.html @@ -3,11 +3,11 @@
- - Delete Entry + + ('form.checkbox.deleteentry'); ?>

-Home +('text.home'); ?> '.$be.' | '; } ?> - New + ('text.new'); ?>

diff --git a/webroot/view/list/list.html b/webroot/view/list/list.html index fc06f15..5caf839 100644 --- a/webroot/view/list/list.html +++ b/webroot/view/list/list.html @@ -1,9 +1,9 @@
- +

- Home | New + ('text.home'); ?> | ('text.new'); ?>

-

Nothing here.

+

('text.noentries'); ?>

-- 2.39.5