You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setlanguage.php 1.7KB

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