translation.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2021 Johannes Keßler
  7. *
  8. * Development starting from 2011: Johannes Keßler
  9. * https://www.bananas-playground.net/projekt/insipid/
  10. *
  11. * creator:
  12. * Luke Reeves <luke@neuro-tech.net>
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  26. *
  27. */
  28. /**
  29. * Class Translation
  30. *
  31. * A very simple way to load and provide the translation
  32. */
  33. class Translation {
  34. /**
  35. * @var string The lang code
  36. */
  37. private $_defaultLangToUse = 'eng';
  38. /**
  39. * @var array The loaded lang information from the file
  40. */
  41. private $_langData = array();
  42. public function __construct() {
  43. $_langFile = ABSOLUTE_PATH.'/lib/lang/'.$this->_defaultLangToUse.'.lang.ini';
  44. if(defined('FRONTEND_LANGUAGE')) {
  45. $_langFile = ABSOLUTE_PATH.'/lib/lang/'.FRONTEND_LANGUAGE.'.lang.ini';
  46. if(file_exists($_langFile)) {
  47. $_langData = parse_ini_file($_langFile);
  48. if($_langData !== false) {
  49. $this->_langData = $_langData;
  50. }
  51. }
  52. }
  53. else {
  54. $_langData = parse_ini_file($_langFile);
  55. if($_langData !== false) {
  56. $this->_langData = $_langData;
  57. }
  58. }
  59. }
  60. /**
  61. * Return text for given key for currently loaded lang
  62. *
  63. * @param $key
  64. * @return string
  65. */
  66. public function t($key) {
  67. $ret = $key;
  68. if(isset($this->_langData[$key])) {
  69. $ret = $this->_langData[$key];
  70. }
  71. return $ret;
  72. }
  73. }