From 7faf93f44afab9753dd9f704cb2421da3f13c408 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 17 Jun 2018 20:54:59 +0100 Subject: [PATCH 1/2] Fix a few issues with internationalization --- po/plume.pot | 2 ++ templates/blogs/new.html.tera | 4 ++-- templates/macros.html.tera | 10 +++++++++- templates/notifications/index.html.tera | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/po/plume.pot b/po/plume.pot index 7d698ede..d64da1b3 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -249,3 +249,5 @@ msgstr "" msgid "You need to be logged in order to edit your profile" msgstr "" +msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" +msgstr "" diff --git a/templates/blogs/new.html.tera b/templates/blogs/new.html.tera index 0f89bced..036cd2a6 100644 --- a/templates/blogs/new.html.tera +++ b/templates/blogs/new.html.tera @@ -10,6 +10,6 @@ - + - | _ {% endblock content %} +{% endblock content %} diff --git a/templates/macros.html.tera b/templates/macros.html.tera index 3cce7285..80ad8024 100644 --- a/templates/macros.html.tera +++ b/templates/macros.html.tera @@ -7,6 +7,14 @@

{{ article.post.title }}

{{ article.post.content | striptags | truncate(length=200) }}

-

By {{ name }} ⋅ {{ article.date | date(format="%B %e") }}

+

+ {{ "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" | _( + link_1='', + name=name, + link_4="") + }} + ⋅ {{ article.date | date(format="%B %e") }}

{% endmacro post_card %} diff --git a/templates/notifications/index.html.tera b/templates/notifications/index.html.tera index bbe79618..194581d5 100644 --- a/templates/notifications/index.html.tera +++ b/templates/notifications/index.html.tera @@ -9,7 +9,7 @@
{% for notification in notifications %}
-

{{ notification.title }}

+

{{ notification.title | _ }}

{% if notification.content %}

{{ notification.content }}

{% endif %} From ae4bcabc537613e27e55815b056986cceee4af3c Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 17 Jun 2018 21:19:27 +0100 Subject: [PATCH 2/2] Make notifications translatable --- .../2018-06-17-200302_notification_add_data/down.sql | 2 ++ .../2018-06-17-200302_notification_add_data/up.sql | 2 ++ po/plume.pot | 12 ++++++++++++ src/models/comments.rs | 3 ++- src/models/follows.rs | 3 ++- src/models/likes.rs | 3 ++- src/models/notifications.rs | 6 ++++-- src/models/reshares.rs | 3 ++- src/schema.rs | 1 + templates/notifications/index.html.tera | 2 +- 10 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 migrations/2018-06-17-200302_notification_add_data/down.sql create mode 100644 migrations/2018-06-17-200302_notification_add_data/up.sql diff --git a/migrations/2018-06-17-200302_notification_add_data/down.sql b/migrations/2018-06-17-200302_notification_add_data/down.sql new file mode 100644 index 00000000..41922c38 --- /dev/null +++ b/migrations/2018-06-17-200302_notification_add_data/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE notifications DROP COLUMN data; diff --git a/migrations/2018-06-17-200302_notification_add_data/up.sql b/migrations/2018-06-17-200302_notification_add_data/up.sql new file mode 100644 index 00000000..f88a7231 --- /dev/null +++ b/migrations/2018-06-17-200302_notification_add_data/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE notifications ADD COLUMN data VARCHAR; diff --git a/po/plume.pot b/po/plume.pot index d64da1b3..1d36fc36 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -251,3 +251,15 @@ msgstr "" msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" msgstr "" + +msgid "{{ data }} reshared your article" +msgstr "" + +msgid "{{ data }} started following you" +msgstr "" + +msgid "{{ data }} liked your article" +msgstr "" + +msgid "{{ data }} commented your article" +msgstr "" diff --git a/src/models/comments.rs b/src/models/comments.rs index ed15465d..75df9df0 100644 --- a/src/models/comments.rs +++ b/src/models/comments.rs @@ -152,7 +152,8 @@ impl Notify for Comment { for author in comment.clone().get_post(conn).get_authors(conn) { let comment = comment.clone(); Notification::insert(conn, NewNotification { - title: format!("{} commented your article", comment.get_author(conn).display_name.clone()), + title: "{{ data }} commented your article".to_string(), + data: Some(comment.get_author(conn).display_name.clone()), content: Some(comment.get_post(conn).title), link: comment.ap_url, user_id: author.id diff --git a/src/models/follows.rs b/src/models/follows.rs index 66005ed7..6ba9385f 100644 --- a/src/models/follows.rs +++ b/src/models/follows.rs @@ -78,7 +78,8 @@ impl Notify for Follow { fn notify(conn: &PgConnection, follow: FollowAct, actor: Id) { let follower = User::from_url(conn, actor.into()).unwrap(); Notification::insert(conn, NewNotification { - title: format!("{} started following you", follower.display_name.clone()), + title: "{{ data }} started following you".to_string(), + data: Some(follower.display_name.clone()), content: None, link: Some(follower.ap_url), user_id: User::from_url(conn, follow.follow_props.object_link::().unwrap().into()).unwrap().id diff --git a/src/models/likes.rs b/src/models/likes.rs index 6c8bb929..2462118a 100644 --- a/src/models/likes.rs +++ b/src/models/likes.rs @@ -118,7 +118,8 @@ impl Notify for Like { for author in post.get_authors(conn) { let post = post.clone(); Notification::insert(conn, NewNotification { - title: format!("{} liked your article", liker.display_name.clone()), + title: "{{ data }} liked your article".to_string(), + data: Some(liker.display_name.clone()), content: Some(post.title), link: Some(post.ap_url), user_id: author.id diff --git a/src/models/notifications.rs b/src/models/notifications.rs index 1087d5cb..e0a9acc9 100644 --- a/src/models/notifications.rs +++ b/src/models/notifications.rs @@ -11,7 +11,8 @@ pub struct Notification { pub content: Option, pub link: Option, pub user_id: i32, - pub creation_date: NaiveDateTime + pub creation_date: NaiveDateTime, + pub data: Option } #[derive(Insertable)] @@ -20,7 +21,8 @@ pub struct NewNotification { pub title: String, pub content: Option, pub link: Option, - pub user_id: i32 + pub user_id: i32, + pub data: Option } impl Notification { diff --git a/src/models/reshares.rs b/src/models/reshares.rs index 8477243d..75537672 100644 --- a/src/models/reshares.rs +++ b/src/models/reshares.rs @@ -120,7 +120,8 @@ impl Notify for Reshare { for author in post.get_authors(conn) { let post = post.clone(); Notification::insert(conn, NewNotification { - title: format!("{} reshared your article", actor.display_name.clone()), + title: "{{ data }} reshared your article".to_string(), + data: Some(actor.display_name.clone()), content: Some(post.title), link: Some(post.ap_url), user_id: author.id diff --git a/src/schema.rs b/src/schema.rs index 9c85dc6f..6614f449 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -74,6 +74,7 @@ table! { link -> Nullable, user_id -> Int4, creation_date -> Timestamp, + data -> Nullable, } } diff --git a/templates/notifications/index.html.tera b/templates/notifications/index.html.tera index 194581d5..50752282 100644 --- a/templates/notifications/index.html.tera +++ b/templates/notifications/index.html.tera @@ -9,7 +9,7 @@