Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language selection to attendee section #590

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public function __construct($params=[]) {
$container->registerService('ContactController', function(IAppContainer $c) {
$request = $c->query('Request');
$contacts = $c->getServer()->getContactsManager();
$config = $c->getServer()->getConfig();
$l10nFactory = $c->getServer()->getL10NFactory();

return new Controller\ContactController($c->getAppName(), $request, $contacts);
return new Controller\ContactController($c->getAppName(), $request, $contacts, $config, $l10nFactory);
});

$container->registerService('EmailController', function(IAppContainer $c) {
Expand Down Expand Up @@ -81,8 +83,10 @@ public function __construct($params=[]) {
$userSession = $c->getServer()->getUserSession();
$config = $c->getServer()->getConfig();
$urlGenerator = $c->getServer()->getURLGenerator();
$l10nFactory = $c->getServer()->getL10NFactory();
$l10n = $c->getServer()->getL10N();

return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $urlGenerator);
return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $urlGenerator, $l10nFactory, $l10n);
});
}

Expand Down
36 changes: 34 additions & 2 deletions controller/contactcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Contacts\IManager;
use OCP\IConfig;
use OCP\IRequest;
use OCP\L10N\IFactory;

class ContactController extends Controller {

Expand All @@ -34,15 +36,29 @@ class ContactController extends Controller {
*/
private $contacts;

/**
* @var IConfig
*/
private $config;

/**
* @var IFactory
*/
private $l10nFactory;


/**
* @param string $appName
* @param IRequest $request an instance of the request
* @param IManager $contacts
* @param IConfig $config
* @param IFactory $l10nFactory
*/
public function __construct($appName, IRequest $request, IManager $contacts) {
public function __construct($appName, IRequest $request, IManager $contacts, IConfig $config, IFactory $l10nFactory) {
parent::__construct($appName, $request);
$this->contacts = $contacts;
$this->config = $config;
$this->l10nFactory = $l10nFactory;
}


Expand Down Expand Up @@ -88,6 +104,7 @@ public function searchLocation($location) {
public function searchAttendee($search) {
$result = $this->contacts->search($search, ['FN', 'EMAIL']);

$defaultLang = $this->l10nFactory->findLanguage();
$contacts = [];
foreach ($result as $r) {
if (!isset($r['EMAIL'])) {
Expand All @@ -99,9 +116,13 @@ public function searchAttendee($search) {
$r['EMAIL'] = [$r['EMAIL']];
}

$lang = $this->getPreferredLanguageFromUidOrDefault($r['UID'], $defaultLang);
$isLocalUser = isset($r['isLocalSystemBook']) && $r['isLocalSystemBook'];

$contacts[] = [
'email' => $r['EMAIL'],
'name' => $name
'name' => $name,
'lang' => $lang
];
}

Expand All @@ -123,4 +144,15 @@ private function getNameFromContact(array $r) {

return $name;
}

/**
* Returns the preferred language of a given user uid or $default instead
*
* @param string $uid
* @param string $default
* @return string
*/
private function getPreferredLanguageFromUidOrDefault($uid, $default) {
return $this->config->getUserValue($uid, 'core', 'lang', $default);
}
}
95 changes: 93 additions & 2 deletions controller/viewcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use OCP\IRequest;
use OCP\IUserSession;
use OCP\IURLGenerator;
use OCP\IL10N;
use OCP\L10N\IFactory;

class ViewController extends Controller {

Expand All @@ -49,19 +51,46 @@ class ViewController extends Controller {
*/
private $userSession;

/**
* @var IFactory
*/
private $l10nFactory;

// TODO(artur): Duplicate: Refactor Language --> NC:Server:PersonalInfo.php
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 [type]
*/
private $l;

/**
* @param string $appName
* @param IRequest $request an instance of the request
* @param IUserSession $userSession
* @param IConfig $config
* @param IURLGenerator $urlGenerator
* @param IFactory $l10nFactory
* @param IL10N $l
*/
public function __construct($appName, IRequest $request, IUserSession $userSession,
IConfig $config, IURLGenerator $urlGenerator) {
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
IConfig $config,
IURLGenerator $urlGenerator,
IFactory $l10nFactory,
IL10N $l
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
$this->l10nFactory = $l10nFactory;
$this->l = $l;
}

/**
Expand Down Expand Up @@ -98,6 +127,65 @@ public function index() {
$initialView = 'month';
}

// TODO(artur): Duplicate: Refactor Language --> NC:Server:PersonalInfo.php
$forceLanguage = $this->config->getSystemValue('force_language', false);
if($forceLanguage !== false) {
return [];
}

$userLang = $this->config->getUserValue($userId, 'core', 'lang', $this->l10nFactory->findLanguage());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does $userId come from? It's not injected into the controller.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it's inside the current scope. Everthing's fine! :)

$languageCodes = $this->l10nFactory->findAvailableLanguages();

$commonLanguages = [];
$languages = [];

foreach($languageCodes as $lang) {
$l = \OC::$server->getL10N('settings', $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 && substr($potentialName, 0, 1) !== '_') {//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;
}
}

// if user language is not available but set somehow: show the actual code as name
if (!is_array($userLang)) {
$userLang = [
'code' => $userLang,
'name' => $userLang,
];
}

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 new TemplateResponse('calendar', 'main', array_merge($templateParameters, [
'initialView' => $initialView,
'emailAddress' => $emailAddress,
Expand All @@ -107,6 +195,9 @@ public function index() {
'isPublic' => false,
'isEmbedded' => false,
'token' => '',
'activelanguage' => $userLang,
'commonlanguages' => $commonLanguages,
'languages' => $languages
]));
}

Expand Down
4 changes: 4 additions & 0 deletions css/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@
.icon-embed {
background-image: url('../../img/embed.svg') !important;
}

.display-inline-block {
display: inline-block;
}
9 changes: 6 additions & 3 deletions js/app/controllers/attendeecontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ app.controller('AttendeeController', function($scope, AutoCompletionService) {
'role': 'REQ-PARTICIPANT',
'rsvp': 'TRUE',
'partstat': 'NEEDS-ACTION',
'cutype': 'INDIVIDUAL'
'cutype': 'INDIVIDUAL',
'lang': OC.getLocale() // Use current user's timezone as a default value
}
});
}
Expand Down Expand Up @@ -96,7 +97,8 @@ app.controller('AttendeeController', function($scope, AutoCompletionService) {
arr.push({
displayname: displayname,
email: email,
name: attendee.name
name: attendee.name,
lang: attendee.lang
});
});
});
Expand All @@ -114,7 +116,8 @@ app.controller('AttendeeController', function($scope, AutoCompletionService) {
role: 'REQ-PARTICIPANT',
rsvp: 'TRUE',
partstat: 'NEEDS-ACTION',
cutype: 'INDIVIDUAL'
cutype: 'INDIVIDUAL',
lang: item.lang
}
});
$scope.nameofattendee = '';
Expand Down
3 changes: 2 additions & 1 deletion js/app/models/simpleEventModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ app.factory('SimpleEvent', function () {
'cutype',
'cn',
'delegated-from',
'delegated-to'
'delegated-to',
'language'
];

const organizerParameters = [
Expand Down
25 changes: 24 additions & 1 deletion templates/part.eventsattendees.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,30 @@
ng-checked="attendee.parameters.role == 'NON-PARTICIPANT'"
ng-click="attendee.parameters.role == 'NON-PARTICIPANT' ? attendee.parameters.role = 'REQ-PARTICIPANT' : attendee.parameters.role = 'NON-PARTICIPANT'"
id="attendeeno_{{$id}}"/>
<label class="label" for="attendeeno_{{$id}}"><?php p($l->t('Does not attend'))?></label>
<label class="label" for="attendeeno_{{$id}}"><?php p($l->t('Does not attend')); ?></label>
</div>
<div class="display-inline-block full-width">
<label class="label" for="attendeelang_{{$id}"><?php p($l->t('Language')); ?>:</label>
<select class="event-select pull-left"
ng-model="attendee.parameters.lang"
ng-selected="attendee.parameters.lang"
id="attendeelang_{{$id}}">

<option value="<?php p($_['activelanguage']['code']); ?>">
<?php p($_['activelanguage']['name']); ?>
</option>
<?php foreach($_['commonlanguages'] as $language): ?>
<option value="<?php p($language['code']); ?>">
<?php p($language['name']); ?>
</option>
<?php endforeach; ?>
<optgroup label="––––––––––"></optgroup>
<?php foreach($_['languages'] as $language): ?>
<option value="<?php p($language['code']); ?>">
<?php p($language['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
</li>
Expand Down