Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] tworzenie strony wielojęzycznej
--free--
post
Post #1





Goście







Witam,


Potrzebuje zrobić stronkę wielojęzyczną.
Znalazłem przykład na necie i stworzyłem

w pliku index.php

  1. <?php
  2. ini_set('display_errors','1');
  3. require('langs/lang.class.php');
  4. __('main_page');
  5. ?>


w folderze /langs są pliki

lang.class.php

  1. <?php
  2.  
  3. class Lang
  4. {
  5. private $languages = array('pl' => 'Polski', 'en' => 'English');
  6. private $current_language = FALSE;
  7. private $lines = array();
  8.  
  9. private static $instance = FALSE;
  10.  
  11. public function __construct()
  12. {
  13. $this->set_language();
  14. }
  15. public function instance()
  16. {
  17. if(self::$instance == FALSE)
  18. {
  19. self::$instance = new Lang;
  20. }
  21.  
  22. return self::$instance;
  23. }
  24. private function set_language()
  25. {
  26. if(isset($_GET['lang']) AND array_key_exists(($lang = strtolower($_GET['lang'])), $this->languages))
  27. {
  28. $this->current_language = $lang;
  29. $_SESSION['site_lang'] = $lang;
  30. }
  31. elseif(isset($_SESSION['site_lang']) AND array_key_exists(($lang = strtolower($_SESSION['site_lang'])), $this->languages))
  32. {
  33. $this->current_language = $lang;
  34. }
  35. else
  36. {
  37. $this->current_language = $this->default_language();
  38. }
  39.  
  40. $this->load_lang_file();
  41. }
  42. private function default_language()
  43. {
  44. return current(array_keys($this->languages));
  45. }
  46. private function load_lang_file()
  47. {
  48. if(file_exists('langs/'.$this->current_language.'.php'))
  49. {
  50. include 'langs/'.$this->current_language.'.php';
  51.  
  52. $this->lines = $lang;
  53. }
  54. }
  55. public static function line($name = FALSE, $params = array())
  56. {
  57. if(isset(self::instance()->lines[$name]))
  58. return vsprintf(self::instance()->lines[$name], $params);
  59.  
  60. return FALSE;
  61. }
  62. public static function get_language()
  63. {
  64. return self::instance()->current_language;
  65. }
  66.  
  67. public static function get_languages()
  68. {
  69. return self::instance()->languages;
  70. }
  71. function __($name = FALSE, $params = array())
  72. {
  73. return Lang::line($name, $params);
  74. }
  75. }


oraz pliki pl.php oraz en.php

gdzie są wpisy :
<?php
$lang['main_page'] = 'Strona główna';
?>


po wywołaniu strony index.php jest błąd :


Fatal error: Call to undefined function __() in C:\Program Files\WebServ\httpd-users\tg\index.php on line 12




Serwer HTTP: Apache/2.2.6 (Win32) PHP/5.2.5
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 19:05