Update rocket_i18n and add gettext_macros (#431)

Internationalization now uses proc-macros that generate the .pot file
automatically.
This commit is contained in:
Baptiste Gelez
2019-02-02 15:23:50 +01:00
committed by GitHub
parent 8696185d1e
commit 7eef4643c8
57 changed files with 6306 additions and 5484 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
@use template_utils::*;
@use routes::*;
@(ctx: BaseContext, title: &str, head: Content, header: Content, content: Content)
@(ctx: BaseContext, title: String, head: Content, header: Content, content: Content)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@i18n!(ctx.1, title) ⋅ @i18n!(ctx.1, "Plume")</title>
<title>@title ⋅ @i18n!(ctx.1, "Plume")</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="@uri!(static_files: file = "css/main.css")" />
<link rel="stylesheet" href="@uri!(static_files: file = "css/feather.css")" />
+3 -3
View File
@@ -7,7 +7,7 @@
@(ctx: BaseContext, blog: Blog, fqn: String, authors: &Vec<User>, total_articles: i64, page: i32, n_pages: i32, is_author: bool, posts: Vec<Post>)
@:base(ctx, blog.title.as_ref(), {}, {
@:base(ctx, blog.title.clone(), {}, {
<a href="@uri!(blogs::details: name = &fqn, page = _)">@blog.title</a>
}, {
<div class="hidden">
@@ -22,13 +22,13 @@
<h1><span class="p-name">@blog.title</span> <small>~@fqn</small></h1>
<p>@blog.summary</p>
<p>
@i18n!(ctx.1, "There's one author on this blog: ", "There are {0} authors on this blog: ", authors.len())
@i18n!(ctx.1, "There's one author on this blog: ", "There are {0} authors on this blog: "; authors.len())
@for author in authors {
<a class="author p-author" href="@uri!(user::details: name = author.get_fqn(ctx.0))">@author.name(ctx.0)</a>
}
</p>
<p>
@i18n!(ctx.1, "There's one article on this blog", "There are {0} articles on this blog", total_articles)
@i18n!(ctx.1, "There's one article on this blog", "There are {0} articles on this blog"; total_articles)
</p>
<section>
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, form: &NewBlogForm, errors: ValidationErrors)
@:base(ctx, "New Blog", {}, {}, {
@:base(ctx, i18n!(ctx.1, "New Blog"), {}, {}, {
<h1>@i18n!(ctx.1, "Create a blog")</h1>
<form method="post" action="@uri!(blogs::create)">
@input!(ctx.1, title (text), "Title", form, errors, "required minlength=\"1\"")
+2 -2
View File
@@ -1,9 +1,9 @@
@use templates::base as base_template;
@use template_utils::*;
@(ctx: BaseContext, error_message: &str, error: Content)
@(ctx: BaseContext, error_message: String, error: Content)
@:base_template(ctx, error_message, {}, {}, {
@:base_template(ctx, error_message.clone(), {}, {}, {
@:error()
<p>@error_message</p>
})
+7 -6
View File
@@ -3,10 +3,11 @@
@(ctx: BaseContext)
@:base(ctx, "", {
<h1>@i18n!(ctx.1, "Invalid CSRF token.")</h1>
<p>@i18n!(ctx.1, r#"Something is wrong with your CSRF token.
Make sure cookies are enabled in you browser, and try reloading this page.
If you continue to see this error message, please report it."#)
</p>
@:base(ctx, i18n!(ctx.1, "Invalid CSRF token"), {
<h1>@i18n!(ctx.1, "Invalid CSRF token")</h1>
<p>
@i18n!(ctx.1,
"Something is wrong with your CSRF token. Make sure cookies are enabled in you browser, and try reloading this page. If you continue to see this error message, please report it."
)
</p>
})
+1 -1
View File
@@ -1,7 +1,7 @@
@use templates::errors::base;
@use template_utils::*;
@(ctx: BaseContext, error_message: &str)
@(ctx: BaseContext, error_message: String)
@:base(ctx, error_message, {
<h1>@i18n!(ctx.1, "You are not authorized.")</h1>
+1 -1
View File
@@ -3,7 +3,7 @@
@(ctx: BaseContext)
@:base(ctx, "Page not found", {
@:base(ctx, i18n!(ctx.1, "Page not found"), {
<h1>@i18n!(ctx.1, "We couldn't find this page.")</h1>
<p>@i18n!(ctx.1, "The link that led you here may be broken.")</p>
})
+1 -1
View File
@@ -3,7 +3,7 @@
@(ctx: BaseContext)
@:base(ctx, "Internal server error", {
@:base(ctx, i18n!(ctx.1, "Internal server error"), {
<h1>@i18n!(ctx.1, "Something broke on our side.")</h1>
<p>@i18n!(ctx.1, "Sorry about that. If you think this is a bug, please report it.")</p>
})
@@ -3,7 +3,7 @@
@(ctx: BaseContext)
@:base(ctx, "Unprocessable entity", {
@:base(ctx, "Unprocessable entity".to_string(), {
<h1>@i18n!(ctx.1, "The content you sent can't be processed.")</h1>
<p>@i18n!(ctx.1, "Maybe it was too long.")</p>
})
+1 -1
View File
@@ -5,7 +5,7 @@
@(ctx: BaseContext, instance: Instance, admin: User, n_users: i64, n_articles: i64, n_instances: i64)
@:base(ctx, i18n!(ctx.1, "About {0}"; instance.name.clone()).as_str(), {}, {}, {
@:base(ctx, i18n!(ctx.1, "About {0}"; instance.name.clone()), {}, {}, {
<h1>@i18n!(ctx.1, "About {0}"; instance.name)</h1>
<section>
@Html(instance.short_description_html)
+1 -1
View File
@@ -7,7 +7,7 @@
@(ctx: BaseContext, instance: Instance, form: InstanceSettingsForm, errors: ValidationErrors)
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()).as_str(), {}, {}, {
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()), {}, {}, {
<h1>@i18n!(ctx.1, "Administration")</h1>
@tabs(&[
+1 -1
View File
@@ -5,7 +5,7 @@
@(ctx: BaseContext, articles: Vec<Post>, page: i32, n_pages: i32)
@:base(ctx, "All the articles of the Fediverse", {}, {}, {
@:base(ctx, i18n!(ctx.1, "All the articles of the Fediverse"), {}, {}, {
<div class="h-feed">
<h1 "p-name">@i18n!(ctx.1, "All the articles of the Fediverse")</h1>
+1 -1
View File
@@ -5,7 +5,7 @@
@(ctx: BaseContext, articles: Vec<Post>, page: i32, n_pages: i32)
@:base(ctx, "Your feed", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Your feed"), {}, {}, {
<h1>@i18n!(ctx.1, "Your feed")</h1>
@tabs(&[
+6 -6
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, local: Vec<Post>, federated: Vec<Post>, user_feed: Option<Vec<Post>>)
@:base(ctx, instance.name.clone().as_ref(), {}, {}, {
@:base(ctx, instance.name.clone(), {}, {}, {
<h1>@i18n!(ctx.1, "Welcome on {}"; instance.name.as_str())</h1>
@if ctx.2.is_some() {
@@ -17,9 +17,9 @@
(&uri!(instance::local: _).to_string(), i18n!(ctx.1, "Local feed"), false),
])
@:home_feed(ctx, user_feed.unwrap_or_default(), &uri!(instance::feed: _).to_string(), "Your feed")
@:home_feed(ctx, federated, &uri!(instance::federated: _).to_string(), "Federated feed")
@:home_feed(ctx, local, &uri!(instance::local: _).to_string(), "Local feed")
@:home_feed(ctx, user_feed.unwrap_or_default(), &uri!(instance::feed: _).to_string(), i18n!(ctx.1, "Your feed"))
@:home_feed(ctx, federated, &uri!(instance::federated: _).to_string(), i18n!(ctx.1, "Federated feed"))
@:home_feed(ctx, local, &uri!(instance::local: _).to_string(), i18n!(ctx.1, "Local feed"))
@:instance_description(ctx, instance, n_users, n_articles)
} else {
@tabs(&[
@@ -28,8 +28,8 @@
(&uri!(instance::local: _).to_string(), i18n!(ctx.1, "Local feed"), false),
])
@:home_feed(ctx, federated, &uri!(instance::federated: _).to_string(), "Federated feed")
@:home_feed(ctx, local, &uri!(instance::local: _).to_string(), "Local feed")
@:home_feed(ctx, federated, &uri!(instance::federated: _).to_string(), i18n!(ctx.1, "Federated feed"))
@:home_feed(ctx, local, &uri!(instance::local: _).to_string(), i18n!(ctx.1, "Local feed"))
@:instance_description(ctx, instance, n_users, n_articles)
}
})
+2 -2
View File
@@ -5,7 +5,7 @@
@(ctx: BaseContext, instance: Instance, instances: Vec<Instance>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()).as_str(), {}, {}, {
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()), {}, {}, {
<h1>@i18n!(ctx.1, "Instances")</h1>
@tabs(&[
@@ -23,7 +23,7 @@
</p>
@if !instance.local {
<form class="inline" method="post" action="@uri!(instance::toggle_block: id = instance.id)">
<input type="submit" value="@i18n!(ctx.1, if instance.blocked { "Unblock" } else { "Block"})">
<input type="submit" value="@if instance.blocked { @i18n!(ctx.1, "Unblock") } else { @i18n!(ctx.1, "Block") }">
</form>
}
</div>
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, instance: Instance, articles: Vec<Post>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Articles from {}"; instance.name.clone()).as_str(), {}, {}, {
@:base(ctx, i18n!(ctx.1, "Articles from {}"; instance.name.clone()), {}, {}, {
<div class="h-feed">
<h1 class="p-name">@i18n!(ctx.1, "Articles from {}"; instance.name)</h1>
+1 -1
View File
@@ -5,7 +5,7 @@
@(ctx: BaseContext, users: Vec<User>, page: i32, n_pages: i32)
@:base(ctx, "Users", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Users"), {}, {}, {
<h1>@i18n!(ctx.1, "Users")</h1>
@tabs(&[
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, media: Media)
@:base(ctx, "Media details", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Media details"), {}, {}, {
<h1>@i18n!(ctx.1, "Media details")</h1>
<section>
<a href="@uri!(medias::list)">@i18n!(ctx.1, "Go back to the gallery")</a>
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, medias: Vec<Media>)
@:base(ctx, "Your media", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Your media"), {}, {}, {
<h1>@i18n!(ctx.1, "Your media")</h1>
<div>
<a href="@uri!(medias::new)" class="inline-block button">@i18n!(ctx.1, "Upload")</a>
+1 -1
View File
@@ -4,7 +4,7 @@
@(ctx: BaseContext)
@:base(ctx, "Media upload", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Media upload"), {}, {}, {
<h1>@i18n!(ctx.1, "Media upload")</h1>
<form method="post" enctype="multipart/form-data" action="@uri!(medias::upload)">
<label for="alt">
+3 -3
View File
@@ -4,7 +4,7 @@
@(ctx: BaseContext, notifications: Vec<Notification>, page: i32, n_pages: i32)
@:base(ctx, "Notifications", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Notifications"), {}, {}, {
<h1>@i18n!(ctx.1, "Notifications")</h1>
<div class="list">
@@ -15,10 +15,10 @@
<h3>
@if let Some(url) = notification.get_url(ctx.0) {
<a href="@url">
@i18n!(ctx.1, notification.get_message(); notification.get_actor(ctx.0).unwrap().name(ctx.0))
@translate_notification(ctx, notification.clone())
</a>
} else {
@i18n!(ctx.1, notification.get_message(); notification.get_actor(ctx.0).unwrap().name(ctx.0))
@translate_notification(ctx, notification.clone())
}
</h3>
@if let Some(post) = notification.get_post(ctx.0) {
+2 -2
View File
@@ -2,11 +2,11 @@
@use plume_models::posts::Post;
@use template_utils::*;
@(ctx: BaseContext, articles: Vec<Post>, link: &str, title: &str)
@(ctx: BaseContext, articles: Vec<Post>, link: &str, title: String)
@if articles.len() > 0 {
<div class="h-feed">
<h2><span class="p-name">@i18n!(ctx.1, title)</span> &mdash; <a href="@link">@i18n!(ctx.1, "View all")</a></h2>
<h2><span class="p-name">@title</span> &mdash; <a href="@link">@i18n!(ctx.1, "View all")</a></h2>
<div class="cards spaced">
@for article in articles {
@:post_card(ctx, article)
+5 -5
View File
@@ -11,7 +11,7 @@
@(ctx: BaseContext, article: Post, blog: Blog, comment_form: &NewCommentForm, comment_errors: ValidationErrors, tags: Vec<Tag>, comments: Vec<CommentTree>, previous_comment: Option<Comment>, n_likes: i64, n_reshares: i64, has_liked: bool, has_reshared: bool, is_following: bool, author: User)
@:base(ctx, &article.title.clone(), {
@:base(ctx, article.title.clone(), {
<meta property="og:title" content="@article.title"/>
<meta property="og:type" content="article"/>
@if article.cover_id.is_some() {
@@ -87,7 +87,7 @@
@if ctx.2.is_some() {
<div class="actions">
<form class="likes" action="@uri!(likes::create: blog = blog.get_fqn(ctx.0), slug = &article.slug)" method="POST">
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes", &n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes", n_likes)">
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)">
@n_likes
</p>
@@ -98,7 +98,7 @@
}
</form>
<form class="reshares" action="@uri!(reshares::create: blog = blog.get_fqn(ctx.0), slug = &article.slug)" method="POST">
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boost", &n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts", n_reshares)">
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boost"; n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts"; n_reshares)">
@n_reshares
</p>
@@ -113,14 +113,14 @@
<p class="center">@i18n!(ctx.1, "Login or use your Fediverse account to interact with this article")</p>
<div class="actions">
<div class="likes">
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes", &n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes", n_likes)">
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)">
@n_likes
</p>
<a href="@uri!(session::new: m = i18n!(ctx.1, "Login to like"))" class="action">@icon!("heart") @i18n!(ctx.1, "Add yours")</a>
</div>
<div class="reshares">
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boost", &n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts", n_reshares)">
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boost"; n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts"; n_reshares)">
@n_reshares
</p>
<a href="@uri!(session::new: m = i18n!(ctx.1, "Login to boost"))" class="action">@icon!("repeat") @i18n!(ctx.1, "Boost")</a>
+4 -10
View File
@@ -8,16 +8,10 @@
@use routes::posts::NewPostForm;
@use routes::*;
@(ctx: BaseContext, blog: Blog, editing: bool, form: &NewPostForm, is_draft: bool, article: Option<Post>, errors: ValidationErrors, medias: Vec<Media>, content_len: u64)
@(ctx: BaseContext, title: String, blog: Blog, editing: bool, form: &NewPostForm, is_draft: bool, article: Option<Post>, errors: ValidationErrors, medias: Vec<Media>, content_len: u64)
@:base(ctx, &i18n!(ctx.1, if editing { "Edit {0}" } else { "New post" }; &form.title), {}, {}, {
<h1>
@if editing {
@i18n!(ctx.1, "Edit {0}"; &form.title)
} else {
@i18n!(ctx.1, "Create a new post")
}
</h1>
@:base(ctx, title.clone(), {}, {}, {
<h1>@title</h1>
@if let Some(article) = article {
<form id="post-form" class="new-post" method="post" action="@uri!(posts::update: blog = blog.actor_id, slug = &article.slug)" content-size="@content_len">
} else {
@@ -27,7 +21,7 @@
@input!(ctx.1, subtitle (optional text), "Subtitle", form, errors.clone(), "")
@if let Some(ValidationErrorsKind::Field(errs)) = errors.clone().errors().get("content") {
@format!(r#"<p class="error">{}</p>"#, i18n!(ctx.1, &*errs[0].message.clone().unwrap_or(Cow::from("Unknown error"))))
@format!(r#"<p class="error">{}</p>"#, errs[0].message.clone().unwrap_or(Cow::from("Unknown error")))
}
<label for="plume-editor">@i18n!(ctx.1, "Content")<small>@i18n!(ctx.1, "Markdown syntax is supported")</small></label>
+2 -2
View File
@@ -3,14 +3,14 @@
@(ctx: BaseContext, now: &str)
@:base(ctx, "Search", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Search"), {}, {}, {
<h1>@i18n!(ctx.1, "Search")</h1>
<form method="get" id="form">
<input id="q" name="q" placeholder="@i18n!(ctx.1, "Your query")" type="search">
<details>
<summary>@i18n!(ctx.1, "Advanced search")</summary>
@input!(ctx.1, title (text), "Article title matching these words", &format!("placeholder=\"{}\"", i18n!(ctx.1, "Title")))
@input!(ctx.1, subtitle (text), "Subtitle matching these words", &format!("placeholder=\"{}\"", i18n!(ctx.1, "Subtitle byline")))
@input!(ctx.1, subtitle (text), "Subtitle matching these words", &format!("placeholder=\"{}\"", i18n!(ctx.1, "Subtitle - byline")))
@input!(ctx.1, content (text), "Content matching these words", &format!("placeholder=\"{}\"", i18n!(ctx.1, "Body content")))
@input!(ctx.1, after (date), "From this date", &format!("max={}", now))
@input!(ctx.1, before (date), "To this date", &format!("max={}", now))
+1 -1
View File
@@ -4,7 +4,7 @@
@(ctx: BaseContext, query_str: &str, articles: Vec<Post>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Search result for \"{0}\""; query_str).as_str(), {}, {}, {
@:base(ctx, i18n!(ctx.1, "Search result for \"{0}\""; query_str), {}, {}, {
<h1>@i18n!(ctx.1, "Search result")</h1>
<p>@query_str</p>
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, message: Option<String>, form: &LoginForm, errors: ValidationErrors)
@:base(ctx, "Login", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Login"), {}, {}, {
<h1>@i18n!(ctx.1, "Login")</h1>
@if let Some(message) = message {
<p>@message</p>
+1 -1
View File
@@ -4,7 +4,7 @@
@(ctx: BaseContext, tag: String, articles: Vec<Post>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Articles tagged \"{0}\""; &tag).as_str(), {}, {}, {
@:base(ctx, i18n!(ctx.1, "Articles tagged \"{0}\""; &tag), {}, {}, {
<h1>@i18n!(ctx.1, "Articles tagged \"{0}\""; &tag)</h1>
@if !articles.is_empty() {
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, blogs: Vec<Blog>, drafts: Vec<Post>)
@:base(ctx, "Your Dashboard", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Your Dashboard"), {}, {}, {
<h1>@i18n!(ctx.1, "Your Dashboard")</h1>
<section>
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, user: User, follows: bool, is_remote: bool, remote_url: String, recents: Vec<Post>, reshares: Vec<Post>)
@:base(ctx, &user.name(ctx.0), {}, {}, {
@:base(ctx, user.name(ctx.0), {}, {}, {
@:header(ctx, &user, follows, is_remote, remote_url)
@tabs(&[
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, form: UpdateUserForm, errors: ValidationErrors)
@:base(ctx, "Edit your account", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Edit your account"), {}, {}, {
@if let Some(u) = ctx.2.clone() {
<h1>@i18n!(ctx.1, "Your Profile")</h1>
<form method="post" action="@uri!(user::update: _name = u.username.clone())">
+1 -1
View File
@@ -5,7 +5,7 @@
@(ctx: BaseContext, user: User, follows: bool, is_remote: bool, remote_url: String, followers: Vec<User>, page: i32, n_pages: i32)
@:base(ctx, &i18n!(ctx.1, "{0}'s followers"; user.name(ctx.0)), {}, {}, {
@:base(ctx, i18n!(ctx.1, "{0}'s followers"; user.name(ctx.0)), {}, {}, {
@:header(ctx, &user, follows, is_remote, remote_url)
@tabs(&[
+1 -1
View File
@@ -6,7 +6,7 @@
@(ctx: BaseContext, enabled: bool, form: &NewUserForm, errors: ValidationErrors)
@:base(ctx, "Create your account", {}, {}, {
@:base(ctx, i18n!(ctx.1, "Create your account"), {}, {}, {
@if enabled {
<h1>@i18n!(ctx.1, "Create an account")</h1>
<form method="post" action="@uri!(user::create)">