Update banner and dialog: texts from the built-in English and Chinese catalog (Ely UPD-1)
This commit is contained in:
2 files changed
+41
-14
No files matched your search
@@ -41,6 +41,16 @@ const EN: &[(&str, &str)] = &[
|
||||
("templates.use", "Use template"),
|
||||
("templates.none", "No template matches"),
|
||||
("comments.reply", "Reply"),
|
||||
("update.title", "Software Update"),
|
||||
("update.available", "Version {version} is available."),
|
||||
("update.downloading", "Downloading {version}… {percent}%"),
|
||||
("update.ready", "Version {version} is ready."),
|
||||
("update.download", "Download"),
|
||||
("update.restart", "Restart to update"),
|
||||
("update.later", "Later"),
|
||||
("update.headline.available", "{name} {version} is available"),
|
||||
("update.headline.ready", "{name} {version} is ready"),
|
||||
("update.current", "You have {current}."),
|
||||
("comments.resolve", "Resolve"),
|
||||
("comments.reopen", "Reopen"),
|
||||
("comments.open", "Open {n}"),
|
||||
@@ -142,6 +152,16 @@ const ZH_CN: &[(&str, &str)] = &[
|
||||
("templates.use", "使用模板"),
|
||||
("templates.none", "没有匹配的模板"),
|
||||
("comments.reply", "回复"),
|
||||
("update.title", "软件更新"),
|
||||
("update.available", "{version} 版可以更新。"),
|
||||
("update.downloading", "正在下载 {version}… {percent}%"),
|
||||
("update.ready", "{version} 版已下载好。"),
|
||||
("update.download", "下载"),
|
||||
("update.restart", "重新启动以更新"),
|
||||
("update.later", "以后"),
|
||||
("update.headline.available", "{name} {version} 可以更新"),
|
||||
("update.headline.ready", "{name} {version} 已下载好"),
|
||||
("update.current", "当前为 {current}。"),
|
||||
("comments.resolve", "解决"),
|
||||
("comments.reopen", "重新打开"),
|
||||
("comments.open", "未解决 {n}"),
|
||||
|
||||
+21
-14
@@ -8,6 +8,7 @@ use gpui::{
|
||||
use super::{Hosted, open_hosted};
|
||||
use crate::{
|
||||
buttons::{Button, ButtonVariant, IconButton},
|
||||
i18n::text,
|
||||
layout::ScrollArea,
|
||||
motion::ProgressBar,
|
||||
primitives::{Icon, IconName},
|
||||
@@ -43,7 +44,7 @@ fn progress_line(state: UpdateState) -> Option<AnyElement> {
|
||||
}
|
||||
}
|
||||
|
||||
fn buttons(state: UpdateState, actions: &Actions, size: ControlSize) -> Vec<Button> {
|
||||
fn buttons(state: UpdateState, actions: &Actions, size: ControlSize, cx: &App) -> Vec<Button> {
|
||||
let wire = |button: Button, action: &Option<Action>| {
|
||||
action.clone().map(|action| {
|
||||
button
|
||||
@@ -52,17 +53,17 @@ fn buttons(state: UpdateState, actions: &Actions, size: ControlSize) -> Vec<Butt
|
||||
})
|
||||
};
|
||||
let later = wire(
|
||||
Button::new("update-later", "Later").variant(ButtonVariant::Ghost),
|
||||
Button::new("update-later", text(cx, "update.later", &[])).variant(ButtonVariant::Ghost),
|
||||
&actions.later,
|
||||
);
|
||||
let main = match state {
|
||||
UpdateState::Available => wire(
|
||||
Button::new("update-download", "Download").primary(),
|
||||
Button::new("update-download", text(cx, "update.download", &[])).primary(),
|
||||
&actions.download,
|
||||
),
|
||||
UpdateState::Downloading(_) => None,
|
||||
UpdateState::Ready => wire(
|
||||
Button::new("update-restart", "Restart to update").primary(),
|
||||
Button::new("update-restart", text(cx, "update.restart", &[])).primary(),
|
||||
&actions.restart,
|
||||
),
|
||||
};
|
||||
@@ -118,14 +119,16 @@ impl UpdateBanner {
|
||||
|
||||
impl RenderOnce for UpdateBanner {
|
||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let version = &self.version;
|
||||
let message = match self.state {
|
||||
UpdateState::Available => format!("Version {} is available.", self.version),
|
||||
UpdateState::Available => text(cx, "update.available", &[("version", version)]),
|
||||
UpdateState::Downloading(value) => {
|
||||
format!("Downloading {}… {}%", self.version, (value * 100.0).round())
|
||||
let percent = (value * 100.0).round().to_string();
|
||||
text(cx, "update.downloading", &[("version", version), ("percent", &percent)])
|
||||
}
|
||||
UpdateState::Ready => format!("Version {} is ready.", self.version),
|
||||
UpdateState::Ready => text(cx, "update.ready", &[("version", version)]),
|
||||
};
|
||||
let theme = cx.theme();
|
||||
let dismiss = self.actions.later.clone();
|
||||
div()
|
||||
.id(self.id)
|
||||
@@ -153,6 +156,7 @@ impl RenderOnce for UpdateBanner {
|
||||
..self.actions.clone()
|
||||
},
|
||||
ControlSize::Sm,
|
||||
cx,
|
||||
))
|
||||
.when_some(dismiss, |banner, dismiss| {
|
||||
banner.child(
|
||||
@@ -210,18 +214,20 @@ impl UpdateDialog {
|
||||
|
||||
pub fn open(self, cx: &mut App) -> anyhow::Result<WindowHandle<Hosted<UpdateDialog>>> {
|
||||
let size = cx.theme().dialog_window();
|
||||
open_hosted("Software Update", size, self, cx)
|
||||
open_hosted(text(cx, "update.title", &[]), size, self, cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UpdateDialog {
|
||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let args = [("name", self.name.as_ref()), ("version", self.version.as_ref())];
|
||||
let headline = match self.state {
|
||||
UpdateState::Ready => text(cx, "update.headline.ready", &args),
|
||||
_ => text(cx, "update.headline.available", &args),
|
||||
};
|
||||
let current = text(cx, "update.current", &[("current", &self.current)]);
|
||||
let theme = cx.theme();
|
||||
let colors = &theme.colors;
|
||||
let headline = match self.state {
|
||||
UpdateState::Ready => format!("{} {} is ready", self.name, self.version),
|
||||
_ => format!("{} {} is available", self.name, self.version),
|
||||
};
|
||||
div()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
@@ -236,7 +242,7 @@ impl RenderOnce for UpdateDialog {
|
||||
.flex_col()
|
||||
.gap_1()
|
||||
.child(Title::new(headline))
|
||||
.child(Caption::new(format!("You have {}.", self.current))),
|
||||
.child(Caption::new(current)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
@@ -265,6 +271,7 @@ impl RenderOnce for UpdateDialog {
|
||||
self.state,
|
||||
&self.actions,
|
||||
ControlSize::Md,
|
||||
cx,
|
||||
)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user