[Rt-commit] rt branch, 4.4/dashboard-language, repushed
Shawn Moore
shawn at bestpractical.com
Fri May 13 13:38:33 EDT 2016
The branch 4.4/dashboard-language was deleted and repushed:
was 01ec29904b891bbaf5617921a1ce784cab40f6a4
now 9e7da569747c0d635467460888645d83c56894cc
1: c7e5608 ! 1: 415264d Add language selector for dashboard subscriptions
@@ -1,6 +1,46 @@
Author: Shawn M Moore <shawn at bestpractical.com>
Add language selector for dashboard subscriptions
+
+diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
+--- a/lib/RT/Dashboard/Mailer.pm
++++ b/lib/RT/Dashboard/Mailer.pm
+@@
+ my $recipients_groups = $recipients->{Groups};
+
+ my @emails;
++ my %recipient_language;
+
+ # add users' emails to email list
+ for my $user_id (@{ $recipients_users || [] }) {
+@@
+ next unless $user->id;
+
+ push @emails, $user->EmailAddress;
++ $recipient_language{$user->EmailAddress} = $user->Lang;
+ }
+
+ # add emails for every group's members
+@@
+ my $users = $group->UserMembersObj;
+ while (my $user = $users->Next) {
+ push @emails, $user->EmailAddress;
++ $recipient_language{$user->EmailAddress} = $user->Lang;
+ }
+ }
+
+ my $email_success = 0;
+ for my $email (uniq @emails) {
+ eval {
++ my $lang = $subscription->SubValue('Language')
++ || $recipient_language{$email}
++ || 'en';
++
++ $currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
++
+ $self->SendDashboard(
+ %args,
+ CurrentUser => $currentuser,
diff --git a/share/html/Dashboards/Render.html b/share/html/Dashboards/Render.html
--- a/share/html/Dashboards/Render.html
@@ -119,7 +159,7 @@
- Time => $good_time,
- Subject => "[example.com] a Monthly b Testing! c\n",
+ Time => $good_time,
-+ Subject => "[example.com] a Monthly b Testing! c\n",
++ Subject => "[example.com] a Mensuel b Testing! c\n",
+ BodyLike => qr/Mes tableaux de bord/,
+ BodyUnlike => qr/My dashboards/,
);
2: 1c4e3cf < -: ------- Use the recipient's language for email dashboards, not subscriber's
3: 01ec299 ! 2: 9e7da56 Add config option EmailDashboardLanguageOrder
@@ -1,6 +1,6 @@
Author: Shawn M Moore <shawn at bestpractical.com>
- Add config for EmailDashboardLanguage
+ Add config option EmailDashboardLanguageOrder
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
--- a/etc/RT_Config.pm.in
@@ -9,59 +9,107 @@
Set(@EmailDashboardRemove, ());
-+=item C<$EmailDashboardLanguage>
++=item C<@EmailDashboardLanguageOrder>
+
-+Lets you set the default language for dashboard emails. Individual
-+subscriptions can override this value by explicitly selecting a language on the
-+dashboard subscribe page. If this config has no value (the default), then each
-+recipient's configured language will be used.
++A list that specifies which language to use for dashboard subscription email.
++There are several special keys:
++
++* _subscription: the language chosen on the dashboard subscription page
++* _recipient: the recipient's language, as chosen on their "About Me" page
++* _subscriber: the subscriber's language, as chosen on their "About Me" page
++
++The first key that produces a value is used for the email. Be aware that users
++may not actually have a language set on their "About Me" page, since RT falls
++back to the language their web browser specifies (and of course in a scheduled
++email dashboard, there is no web browser).
++
++You may also include a specific language as a fallback when there is no
++language specified otherwise. Using a specific language never fails to produce
++a value, so subsequent values in the list will never be considered.
++
++By default, RT examines the subscription, then the recipient, then subscriber,
++then finally falls back to English.
++
++See also L</@LexiconLanguages>.
+
+=cut
+
-+# Set($EmailDashboardLanguage, "fr");
++Set(@EmailDashboardLanguageOrder, qw(_subscription _recipient _subscriber en));
+
=back
+diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
+--- a/lib/RT/Config.pm
++++ b/lib/RT/Config.pm
+@@
+ },
+ GnuPGOptions => { Type => 'HASH' },
+ ReferrerWhitelist => { Type => 'ARRAY' },
++ EmailDashboardLanguageOrder => { Type => 'ARRAY' },
+ WebPath => {
+ PostLoadCheck => sub {
+ my $self = shift;
+
diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@
- }
- }
+ my $currentuser = RT::CurrentUser->new;
+ $currentuser->LoadByName($user->Name);
-+ my $lang;
-+ if ($lang = $subscription->SubValue('Language')) {
-+ $RT::Logger->debug("Using subscription's preferred language $lang");
-+ }
-+ elsif ($lang = RT->Config->Get('EmailDashboardLanguage')) {
-+ $RT::Logger->debug("Using RT's preferred language $lang");
-+ }
-+ else {
-+ $RT::Logger->debug("Using each user's preferred language");
-+ }
++ my $subscriber_lang = $user->Lang;
+
+ # look through this user's subscriptions, are any supposed to be generated
+ # right now?
+ for my $subscription ($user->Attributes->Named('Subscription')) {
+@@
my $email_success = 0;
for my $email (uniq @emails) {
eval {
- my $currentuser = RT::CurrentUser->new;
- $currentuser->LoadByEmail($email);
+- my $lang = $subscription->SubValue('Language')
+- || $recipient_language{$email}
+- || 'en';
++ my $lang;
++ for my $langkey (RT->Config->Get('EmailDashboardLanguageOrder')) {
++ if ($langkey eq '_subscription') {
++ if ($lang = $subscription->SubValue('Language')) {
++ $RT::Logger->debug("Using subscription's specified language '$lang'");
++ last;
++ }
++ }
++ elsif ($langkey eq '_recipient') {
++ if ($lang = $recipient_language{$email}) {
++ $RT::Logger->debug("Using recipient's preferred language '$lang'");
++ last;
++ }
++ }
++ elsif ($langkey eq '_subscriber') {
++ if ($lang = $subscriber_lang) {
++ $RT::Logger->debug("Using subscriber's preferred language '$lang'");
++ last;
++ }
++ }
++ else { # specific language name
++ $lang = $langkey;
++ $RT::Logger->debug("Using EmailDashboardLanguageOrder fallback language '$lang'");
++ last;
++ }
++ }
++
++ # use English as the absolute fallback. Though the config
++ # lets you specify a site-specific fallback, it also lets
++ # you not specify a fallback, and we don't want to
++ # accidentally reuse whatever language the previous
++ # recipient happened to have
++ if (!$lang) {
++ $RT::Logger->debug("Using RT's fallback language 'en'. You may specify a different fallback language in your config with EmailDashboardLanguageOrder.");
++ $lang = 'en';
++ }
-- if (my $lang = $subscription->SubValue('Language')) {
-+ if ($lang) {
- $currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
- }
+ $currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
-@@
- $currentuser->loc($frequency_display),
- $dashboard->Name;
-
-+ $RT::Logger->debug("Localized subject: $subject");
-+
- my $entity = $self->BuildEmail(
- %args,
- To => $email,
diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
--- a/t/mail/dashboards.t
@@ -70,7 +118,7 @@
RT::Test->stop_server;
RT->Config->Set('EmailDashboardRemove' => ());
-+RT->Config->Set('EmailDashboardLanguage' => 'fr');
++RT->Config->Set('EmailDashboardLanguageOrder' => qw(_subscription _recipient _subscriber fr));
RT->Config->Set('DashboardAddress' => 'root');
($baseurl, $m) = RT::Test->started_ok;
$m->login;
More information about the rt-commit
mailing list