language.php 852 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. $config = parse_ini_file(__DIR__.'/config/config.ini',true);
  3. $locale = '';
  4. if(isset($_COOKIE['lang'])) $locale = $_COOKIE['lang'];
  5. else $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  6. if(!file_exists(__DIR__.'/locale/'.$locale)) {
  7. $locale = $config['App']['default_language'];
  8. }
  9. if(function_exists("putenv")) {
  10. putenv('LC_ALL='.$locale);
  11. }
  12. if(!setlocale(LC_ALL,$locale)) setlocale(LC_ALL,'0');
  13. bindtextdomain('messages',__DIR__.'/locale');
  14. bind_textdomain_codeset('messages','UTF-8');
  15. textdomain('messages');
  16. if(!function_exists('gettext')) {
  17. function gettext($context,$msgid) {
  18. $contextString = "{$context}\004{$msgid}";
  19. $translation = _($contextString);
  20. if($translation == $contextString) return $msgid;
  21. else return $translation;
  22. }
  23. }
  24. $lang = explode('_',$locale);
  25. if(count($lang)==2) $lang = $lang[0];
  26. else $lang = 'en';
  27. ?>