setlanguage.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Christopher Schäpers <kondou@ts.unde.re>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. $l = \OC::$server->getL10N('settings');
  27. OC_JSON::checkLoggedIn();
  28. OCP\JSON::callCheck();
  29. // Get data
  30. if( isset( $_POST['lang'] ) ) {
  31. $languageCodes=OC_L10N::findAvailableLanguages();
  32. $lang = (string)$_POST['lang'];
  33. if(array_search($lang, $languageCodes) or $lang === 'en') {
  34. \OC::$server->getConfig()->setUserValue( OC_User::getUser(), 'core', 'lang', $lang );
  35. OC_JSON::success(array("data" => array( "message" => $l->t("Language changed") )));
  36. }else{
  37. OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") )));
  38. }
  39. }else{
  40. OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") )));
  41. }