From: Roland Haeder Date: Tue, 10 Mar 2015 02:11:53 +0000 (+0100) Subject: Added basic language support for sending out invitations: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=73da5d8467b9bfc3b659aad01d778f919168d6b9;p=quix0rs-gnu-social.git Added basic language support for sending out invitations: - This allows for example sending German mails from an English instance - Added some checked type-hints (all around language stuff) Some code improvement: - array $foo=null and then an is_null($foo) makes no sense, better use array $foo=array() directly. - onTitle()'s parameter $paths now always must be an array Signed-off-by: Roland Haeder This conflict was because 'master' has StatusNet as class, but 'nigtly' already has GNUSocial as class name. Conflicts: lib/docfile.php Signed-off-by: Roland Haeder --- diff --git a/actions/invite.php b/actions/invite.php index 2853fb0707..b6e0ba8dd1 100644 --- a/actions/invite.php +++ b/actions/invite.php @@ -74,6 +74,7 @@ class InviteAction extends Action $bestname = $profile->getBestName(); $sitename = common_config('site', 'name'); $personal = $this->trimmed('personal'); + $language = $this->trimmed('language'); $addresses = explode("\n", $this->trimmed('addresses')); foreach ($addresses as $email) { @@ -128,7 +129,7 @@ class InviteAction extends Action } catch (NoSuchUserException $e) { // If email was not known, let's send an invite! $this->sent[] = $email; - $this->sendInvitation($email, $user, $personal); + $this->sendInvitation($email, $user, $personal, $language); } } @@ -248,7 +249,7 @@ class InviteAction extends Action } } - function sendInvitation($email, $user, $personal) + function sendInvitation($email, $user, $personal, $language) { $profile = $user->getProfile(); $bestname = $profile->getBestName(); @@ -284,7 +285,7 @@ class InviteAction extends Action $title = (empty($personal)) ? 'invite' : 'invitepersonal'; // @todo FIXME: i18n issue. - $inviteTemplate = DocFile::forTitle($title, DocFile::mailPaths()); + $inviteTemplate = DocFile::forTitle($title, DocFile::mailPaths(), $language); $body = $inviteTemplate->toHTML(array('inviter' => $bestname, 'inviterurl' => $profile->profileurl, diff --git a/lib/docfile.php b/lib/docfile.php index e396870695..2e2afbd014 100644 --- a/lib/docfile.php +++ b/lib/docfile.php @@ -55,12 +55,8 @@ class DocFile $this->filename = $filename; } - static function forTitle($title, $paths) + static function forTitle($title, array $paths, $language=null) { - if (!is_array($paths)) { - $paths = array($paths); - } - $filename = null; if (Event::handle('StartDocFileForTitle', array($title, &$paths, &$filename))) { @@ -80,7 +76,7 @@ class DocFile } if (!empty($lang) || !empty($def)) { - $filename = self::negotiateLanguage($lang, $def); + $filename = self::negotiateLanguage($lang, $def, $language); break; } } @@ -95,12 +91,8 @@ class DocFile } } - function toHTML($args=null) + function toHTML(array $args=array()) { - if (is_null($args)) { - $args = array(); - } - if (empty($this->contents)) { $this->contents = file_get_contents($this->filename); } @@ -114,7 +106,7 @@ class DocFile INSTALLDIR.'/doc-src/'); $site = StatusNet::currentSite(); - + if (!empty($site)) { array_unshift($paths, INSTALLDIR.'/local/doc-src/'.$site.'/'); } @@ -128,7 +120,7 @@ class DocFile INSTALLDIR.'/mail-src/'); $site = StatusNet::currentSite(); - + if (!empty($site)) { array_unshift($paths, INSTALLDIR.'/local/mail-src/'.$site.'/'); } @@ -136,12 +128,20 @@ class DocFile return $paths; } - static function negotiateLanguage($filenames, $defaultFilename=null) + private static function negotiateLanguage(array $filenames, $defaultFilename=null, $language = null) { - // XXX: do this better - + // Default is current language $langcode = common_language(); + // Is a language set? + if (!empty($language)) { + // And is it valid? + if (common_valid_language($language)) { + // Use this as language (e.g. from form) + $langcode = strval($language); + } + } + foreach ($filenames as $filename) { if (preg_match('/\.'.$langcode.'$/', $filename)) { return $filename; diff --git a/lib/inviteform.php b/lib/inviteform.php index 364ca75b9b..be4dc163b0 100644 --- a/lib/inviteform.php +++ b/lib/inviteform.php @@ -93,6 +93,7 @@ class InviteForm extends Form function formData() { $this->out->elementStart('ul', 'form_data'); + $this->out->elementStart('li'); $this->out->textarea( 'addresses', @@ -103,6 +104,7 @@ class InviteForm extends Form _('Addresses of friends to invite (one per line).') ); $this->out->elementEnd('li'); + $this->out->elementStart('li'); $this->out->textarea( // TRANS: Field label for a personal message to send to invitees. @@ -112,6 +114,16 @@ class InviteForm extends Form _('Optionally add a personal message to the invitation.') ); $this->out->elementEnd('li'); + + $language = common_language(); + + $this->out->elementStart('li'); + $this->out->dropdown('language', _('Language'), + // TRANS: Tooltip for dropdown list label in form for profile settings. + get_nice_language_list(), _('Preferred language.'), + false, $language); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); } diff --git a/plugins/EmailRegistration/EmailRegistrationPlugin.php b/plugins/EmailRegistration/EmailRegistrationPlugin.php index 330f72b15b..77ac763bd0 100644 --- a/plugins/EmailRegistration/EmailRegistrationPlugin.php +++ b/plugins/EmailRegistration/EmailRegistrationPlugin.php @@ -72,7 +72,7 @@ class EmailRegistrationPlugin extends Plugin $dir = dirname(__FILE__); // @todo FIXME: i18n issue. - $docFile = DocFile::forTitle($title, $dir.'/doc-src/'); + $docFile = DocFile::forTitle($title, array($dir . '/doc-src/')); if (!empty($docFile)) { $output = $docFile->toHTML(); @@ -163,7 +163,7 @@ class EmailRegistrationPlugin extends Plugin mail_send($recipients, $headers, $body); } - function onEndDocFileForTitle($title, $paths, &$filename) + function onEndDocFileForTitle($title, array $paths, &$filename) { if ($title == 'confirmemailreg' && empty($filename)) { $filename = dirname(__FILE__).'/mail-src/'.$title; diff --git a/plugins/EmailReminder/EmailReminderPlugin.php b/plugins/EmailReminder/EmailReminderPlugin.php index a415865ab9..9ba3d125e1 100644 --- a/plugins/EmailReminder/EmailReminderPlugin.php +++ b/plugins/EmailReminder/EmailReminderPlugin.php @@ -77,7 +77,7 @@ class EmailReminderPlugin extends Plugin return true; } - function onEndDocFileForTitle($title, $paths, &$filename) + function onEndDocFileForTitle($title, array $paths, &$filename) { if (empty($filename)) { $filename = dirname(__FILE__) . '/mail-src/' . $title; @@ -127,6 +127,7 @@ class EmailReminderPlugin extends Plugin * Send a real live email reminder * * @todo This would probably be better as two or more sep functions + * @todo Add language support? * * @param string $type type of reminder * @param mixed $object Confirm_address or Invitation object