summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-04-07 12:39:11 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-05-16 09:50:21 +0200
commit6ada8254c9da63638f3b7e0cceaacf4254f43916 (patch)
treef12b324fe26db57dbbebe1c1e9491409696c164a /lib
parent85f5ae9264c6cf8dcdcd061f0e5d8008f745a596 (diff)
downloadnextcloud-server-6ada8254c9da63638f3b7e0cceaacf4254f43916.tar.gz
nextcloud-server-6ada8254c9da63638f3b7e0cceaacf4254f43916.zip
Added language support in users list
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/L10N/Factory.php81
-rw-r--r--lib/private/Settings/Personal/PersonalInfo.php72
2 files changed, 94 insertions, 59 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php
index a7ffb401b7b..759340a63c3 100644
--- a/lib/private/L10N/Factory.php
+++ b/lib/private/L10N/Factory.php
@@ -59,6 +59,11 @@ class Factory implements IFactory {
*/
protected $pluralFunctions = [];
+ const COMMON_LANGUAGE_CODES = [
+ 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
+ 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
+ ];
+
/** @var IConfig */
protected $config;
@@ -137,9 +142,9 @@ class Factory implements IFactory {
*
* @link https://github.com/owncloud/core/issues/21955
*/
- if($this->config->getSystemValue('installed', false)) {
+ if ($this->config->getSystemValue('installed', false)) {
$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null;
- if(!is_null($userId)) {
+ if (!is_null($userId)) {
$userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
} else {
$userLang = null;
@@ -310,7 +315,7 @@ class Factory implements IFactory {
*/
private function isSubDirectory($sub, $parent) {
// Check whether $sub contains no ".."
- if(strpos($sub, '..') !== false) {
+ if (strpos($sub, '..') !== false) {
return false;
}
@@ -441,4 +446,74 @@ class Factory implements IFactory {
return $function;
}
}
+
+ /**
+ * returns the common language and other languages in an
+ * associative array
+ *
+ * @return array
+ */
+ public function getLanguages() {
+ $forceLanguage = $this->config->getSystemValue('force_language', false);
+ if ($forceLanguage !== false) {
+ return [];
+ }
+
+ $languageCodes = $this->findAvailableLanguages();
+
+ $commonLanguages = [];
+ $languages = [];
+
+ foreach($languageCodes as $lang) {
+ $l = $this->get('lib', $lang);
+ // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
+ $potentialName = (string) $l->t('__language_name__');
+ if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
+ $ln = array(
+ 'code' => $lang,
+ 'name' => $potentialName
+ );
+ } else if ($lang === 'en') {
+ $ln = array(
+ 'code' => $lang,
+ 'name' => 'English (US)'
+ );
+ } else {//fallback to language code
+ $ln = array(
+ 'code' => $lang,
+ 'name' => $lang
+ );
+ }
+
+ // put appropriate languages into appropriate arrays, to print them sorted
+ // common languages -> divider -> other languages
+ if (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
+ $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)] = $ln;
+ } else {
+ $languages[] = $ln;
+ }
+ }
+
+ ksort($commonLanguages);
+
+ // sort now by displayed language not the iso-code
+ usort( $languages, function ($a, $b) {
+ if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
+ // If a doesn't have a name, but b does, list b before a
+ return 1;
+ }
+ if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
+ // If a does have a name, but b doesn't, list a before b
+ return -1;
+ }
+ // Otherwise compare the names
+ return strcmp($a['name'], $b['name']);
+ });
+
+ return [
+ // reset indexes
+ 'commonlanguages' => array_values($commonLanguages),
+ 'languages' => $languages
+ ];
+ }
}
diff --git a/lib/private/Settings/Personal/PersonalInfo.php b/lib/private/Settings/Personal/PersonalInfo.php
index 813d06195b5..305e3fb0a4d 100644
--- a/lib/private/Settings/Personal/PersonalInfo.php
+++ b/lib/private/Settings/Personal/PersonalInfo.php
@@ -39,6 +39,7 @@ use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
class PersonalInfo implements ISettings {
+
/** @var IConfig */
private $config;
/** @var IUserManager */
@@ -51,12 +52,6 @@ class PersonalInfo implements ISettings {
private $appManager;
/** @var IFactory */
private $l10nFactory;
-
- const COMMON_LANGUAGE_CODES = [
- 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
- 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
- ];
-
/** @var IL10N */
private $l;
@@ -198,64 +193,29 @@ class PersonalInfo implements ISettings {
$uid = $user->getUID();
- $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
- $languageCodes = $this->l10nFactory->findAvailableLanguages();
-
- $commonLanguages = [];
- $languages = [];
+ $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
+ $languages = $this->l10nFactory->getLanguages();
- foreach($languageCodes as $lang) {
- $l = \OC::$server->getL10N('lib', $lang);
- // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
- $potentialName = (string) $l->t('__language_name__');
- if($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
- $ln = array('code' => $lang, 'name' => $potentialName);
- } elseif ($lang === 'en') {
- $ln = ['code' => $lang, 'name' => 'English (US)'];
- }else{//fallback to language code
- $ln=array('code'=>$lang, 'name'=>$lang);
- }
-
- // put appropriate languages into appropriate arrays, to print them sorted
- // used language -> common languages -> divider -> other languages
- if ($lang === $userLang) {
- $userLang = $ln;
- } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
- $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln;
- } else {
- $languages[]=$ln;
- }
+ // associate the user language with the proper array
+ $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code'));
+ $userLang = $languages['commonlanguages'][$userLangIndex];
+ // search in the other languages
+ if ($userLangIndex === false) {
+ $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code'));
+ $userLang = $languages['languages'][$userLangIndex];
}
-
// if user language is not available but set somehow: show the actual code as name
if (!is_array($userLang)) {
$userLang = [
- 'code' => $userLang,
- 'name' => $userLang,
+ 'code' => $userConfLang,
+ 'name' => $userConfLang,
];
}
- ksort($commonLanguages);
-
- // sort now by displayed language not the iso-code
- usort( $languages, function ($a, $b) {
- if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
- // If a doesn't have a name, but b does, list b before a
- return 1;
- }
- if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
- // If a does have a name, but b doesn't, list a before b
- return -1;
- }
- // Otherwise compare the names
- return strcmp($a['name'], $b['name']);
- });
-
- return [
- 'activelanguage' => $userLang,
- 'commonlanguages' => $commonLanguages,
- 'languages' => $languages
- ];
+ return array_merge(
+ array('activelanguage' => $userLang),
+ $languages
+ );
}
/**