config.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /* Wifi Hotspot app for YunoHost
  3. * Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  4. * Contribute at https://github.com/jvaubourg/hotspot_ynh
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. // Framework configuration
  20. function configure() {
  21. option('env', ENV_PRODUCTION);
  22. option('debug', false);
  23. option('base_uri', '<TPL:NGINX_LOCATION>/');
  24. layout("layout.html.php");
  25. define('PUBLIC_DIR', '<TPL:NGINX_LOCATION>/public');
  26. }
  27. // Gettext function
  28. function _($string) {
  29. return gettext($string);
  30. }
  31. // Before routing
  32. function before($route) {
  33. $lang_mapping = array(
  34. 'fr' => 'fr_FR'
  35. );
  36. if(!isset($_SESSION['locale'])) {
  37. $locale = explode(',', $_SERVER['HTTP_ACCEP_LANGUAGE']);
  38. $_SESSION['locale'] = strtolower(substr(chop($locale[0]), 0, 2));
  39. }
  40. $lang = $_SESSION['locale'];
  41. // Convert simple language code into full language code
  42. if(array_key_exists($lang, $lang_mapping)) {
  43. $lang = $lang_mapping[$lang];
  44. }
  45. $lang = "$lang.utf8";
  46. $textdomain = "localization";
  47. putenv("LANGUAGE=$lang");
  48. putenv("LANG=$lang");
  49. putenv("LC_ALL=$lang");
  50. putenv("LC_MESSAGES=$lang");
  51. setlocale(LC_ALL, $lang);
  52. setlocale(LC_CTYPE, $lang);
  53. $locales_dir = dirname(__FILE__).'/i18n';
  54. bindtextdomain($textdomain, $locales_dir);
  55. bind_textdomain_codeset($textdomain, 'UTF-8');
  56. textdomain($textdomain);
  57. set('locale', $lang);
  58. }
  59. // After routing
  60. function after($output, $route) {
  61. return $output;
  62. }