Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2021-08-14 03:23:39 +0300
committerChristopher Ng <chrng8@gmail.com>2021-08-27 08:06:12 +0300
commitc65987213c24a721e8d250fd508c3b5940738cd5 (patch)
tree9d3b6ea992dc04950d716b0a73f9bee4d32838d4 /apps/settings/src
parentcc5815dcd0342a521be400f35cbc8a666b83046d (diff)
Create language service and update constants
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/settings/src')
-rw-r--r--apps/settings/src/constants/AccountPropertyConstants.js10
-rw-r--r--apps/settings/src/service/PersonalInfo/LanguageService.js48
2 files changed, 58 insertions, 0 deletions
diff --git a/apps/settings/src/constants/AccountPropertyConstants.js b/apps/settings/src/constants/AccountPropertyConstants.js
index 19d4814e1c0..0288ee679ce 100644
--- a/apps/settings/src/constants/AccountPropertyConstants.js
+++ b/apps/settings/src/constants/AccountPropertyConstants.js
@@ -50,6 +50,16 @@ export const ACCOUNT_PROPERTY_READABLE_ENUM = Object.freeze({
WEBSITE: t('settings', 'Website'),
})
+/** Enum of setting properties */
+export const SETTING_PROPERTY_ENUM = Object.freeze({
+ LANGUAGE: 'language',
+})
+
+/** Enum of setting properties to human readable setting properties */
+export const SETTING_PROPERTY_READABLE_ENUM = Object.freeze({
+ LANGUAGE: 'Language',
+})
+
/** Enum of scopes */
export const SCOPE_ENUM = Object.freeze({
LOCAL: 'v2-local',
diff --git a/apps/settings/src/service/PersonalInfo/LanguageService.js b/apps/settings/src/service/PersonalInfo/LanguageService.js
new file mode 100644
index 00000000000..56868f208f7
--- /dev/null
+++ b/apps/settings/src/service/PersonalInfo/LanguageService.js
@@ -0,0 +1,48 @@
+/**
+ * @copyright 2021, Christopher Ng <chrng8@gmail.com>
+ *
+ * @author Christopher Ng <chrng8@gmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import axios from '@nextcloud/axios'
+import { getCurrentUser } from '@nextcloud/auth'
+import { generateOcsUrl } from '@nextcloud/router'
+import confirmPassword from '@nextcloud/password-confirmation'
+
+import { SETTING_PROPERTY_ENUM } from '../../constants/AccountPropertyConstants'
+
+/**
+ * Save the language of the user
+ *
+ * @param {string} languageCode the language code
+ * @returns {object}
+ */
+export const saveLanguage = async(languageCode) => {
+ const userId = getCurrentUser().uid
+ const url = generateOcsUrl('cloud/users/{userId}', { userId })
+
+ await confirmPassword()
+
+ const res = await axios.put(url, {
+ key: SETTING_PROPERTY_ENUM.LANGUAGE,
+ value: languageCode,
+ })
+
+ return res.data
+}