config.php 2.0 KB

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