From: Johannes Keßler Date: Fri, 18 Nov 2022 11:59:48 +0000 (+0100) Subject: i18n now available X-Git-Tag: 1.1~23 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=0dd2d04c91775c8ccf1da914e0a0891de8d5e887;p=scientia.git i18n now available --- 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'); ?>