Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add I18n support example by use rust-i18n #3

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 177 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ members = [
"crates/headless",
"crates/html_to_markdown",
"crates/http",
"crates/i18n",
"crates/image_viewer",
"crates/indexed_docs",
"crates/inline_completion_button",
Expand Down Expand Up @@ -196,6 +197,7 @@ gpui_macros = { path = "crates/gpui_macros" }
headless = { path = "crates/headless" }
html_to_markdown = { path = "crates/html_to_markdown" }
http = { path = "crates/http" }
i18n = { path = "crates/i18n" }
image_viewer = { path = "crates/image_viewer" }
indexed_docs = { path = "crates/indexed_docs" }
inline_completion_button = { path = "crates/inline_completion_button" }
Expand Down
108 changes: 108 additions & 0 deletions assets/locales/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
About Zed…: 关于 Zed…
Add Cursor Above: 在上方添加光标
Add Cursor Below: 在下方添加光标
Add Folder to Project…: 添加文件夹到项目…
Open a new Project…: 打开新项目…
Open Recent Projects…: 打开最近的项目…
Back: 后退
Check for Updates: 检查更新
Close All Docks: 关闭所有面板
Close Editor: 关闭编辑器
Close Window: 关闭窗口
Collab Panel: 协作面板
Open Application Menu: 打开应用菜单
Command Palette…: 命令面板…
Copy: 复制
Cut: 剪切
Diagnostics: 诊断信息
Documentation: 文档
Duplicate Selection: 复制已选内容
Edit: 编辑
Editor Layout: 编辑器布局
Expand Selection: 扩展选择
Extensions: 扩展
File: 文件
Find All References: 查找所有引用
Find In Project: 在项目中查找
Find: 查找
Forward: 前进
Give Feedback…: 提交反馈…
Go to Definition: 转到定义
Go to File…: 转到文件…
Go to Line/Column…: 转到行/列…
Go to Symbol in Editor…: 转到符号…
Go to Type Definition: 转到类型定义
Go: 转到
Help: 帮助
Hide Others: 隐藏其他
Hide Zed: 隐藏 Zed
Install CLI: 安装 CLI 工具
Minimize: 最小化
Move Line Down: 向下移动行
Move Line Up: 向上移动行
New Window: 新建窗口
New: 新建
Next Problem: 下一个问题
Open Default Key Bindings: 默认按键绑定
Open Default Settings: 默认设置
Open Key Bindings: 按键绑定
Open Local Settings: 打开工作区设置
Open Recent…: 打开最近…
Open Settings: 用户设置
Open…: 打开…
Outline Panel: 大纲面板
Paste: 粘贴
Preferences: 首选项
Previous Problem:
Project Panel: 项目面板
Quit: 退出
Redo: 重做
Reset Zoom: 重置缩放
Save All: 全部保存
Save As…: 另存为…
Save: 保存
Select All: 全选
Select Next Occurrence: 选择下一个相同文本
Select Theme…: 选择主题…
Selection: 选择
Settings: 设置
Show All: 显示全部
Show Welcome: 显示欢迎页
Shrink Selection: 缩小选择
Sign in: 登录
Sign Out: 登出
Split Down: 向下拆分
Split Left: 向左拆分
Split Right: 向右拆分
Split Up: 向上拆分
Terminal Panel: 终端面板
Themes…: 主题…
Toggle Bottom Dock: 开/关底部面板
Toggle Left Dock: 开关左侧面板
Toggle Line Comment: 切换行注释
Toggle Right Dock: 开关右侧面板
Toggle User Menu: 切换用户菜单
Undo: 撤销
View Dependency Licenses: 查看三方库协议
View Telemetry: 查看遥测日志
View: 视图
Window: 窗口
Zoom In: 放大
Zoom Out: 缩小
Zoom: 缩放
Sign In: 登录
Sign in to enable collaboration.: 登录以启用协作
Generate and analyze code with language models. You can dialog with the assistant in this panel or transform code inline.: 使用语言模型生成和分析代码。您可以在此面板中与助手对话,或者在行内转换代码。
Notifications: 通知
"Work with your team in realtime with collaborative editing, voice, shared notes and more.": "通过协作编辑、语音、共享笔记等功能与团队实时合作。"
You are not currently signed in to Zed. Currently the remote development featuers are only available to signed in users. Please sign in to continue.: 您当前未登录 Zed。目前远程开发功能仅对登录用户开放。请登录以继续。
"No dev servers registered.": "未注册开发服务器。"
"Dev Servers": "开发服务器"
"New Server": 新增服务器
"Register a new dev server": 注册新的开发服务器
Key Bindings: 按键绑定
Workspace: 工作区
Open Command Palette: 打开命令面板
Buffer Font Size: 编辑区字体尺寸
UI Font Size: 界面字体尺寸
Project: 项目
2 changes: 2 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"light": "One Light",
"dark": "One Dark"
},
// The UI language, which can be one of: en, zh-CN
"locale": "en",
// The name of a base set of key bindings to use.
// This setting can take four values, each named after another
// text editor:
Expand Down
1 change: 1 addition & 0 deletions crates/assets/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rust_embed::RustEmbed;
#[include = "themes/**/*"]
#[exclude = "themes/src/*"]
#[include = "sounds/**/*"]
#[include = "locales/*"]
#[include = "*.md"]
#[exclude = "*.DS_Store"]
pub struct Assets;
Expand Down
1 change: 1 addition & 0 deletions crates/assistant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ gpui.workspace = true
heed.workspace = true
html_to_markdown.workspace = true
http.workspace = true
i18n.workspace = true
indexed_docs.workspace = true
indoc.workspace = true
language.workspace = true
Expand Down
9 changes: 4 additions & 5 deletions crates/assistant/src/completion_provider/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::{anyhow, Result};
use client::{proto, Client};
use futures::{future::BoxFuture, stream::BoxStream, FutureExt, StreamExt, TryFutureExt};
use gpui::{AnyView, AppContext, Task};
use i18n::t;
use std::{future, sync::Arc};
use strum::IntoEnumIterator;
use ui::prelude::*;
Expand Down Expand Up @@ -178,13 +179,11 @@ struct AuthenticationPrompt;

impl Render for AuthenticationPrompt {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
const LABEL: &str = "Generate and analyze code with language models. You can dialog with the assistant in this panel or transform code inline.";

v_flex().gap_6().p_4().child(Label::new(LABEL)).child(
v_flex().gap_6().p_4().child(Label::new(t!("Generate and analyze code with language models. You can dialog with the assistant in this panel or transform code inline."))).child(
v_flex()
.gap_2()
.child(
Button::new("sign_in", "Sign in")
Button::new("sign_in", t!("Sign in"))
.icon_color(Color::Muted)
.icon(IconName::Github)
.icon_position(IconPosition::Start)
Expand All @@ -198,7 +197,7 @@ impl Render for AuthenticationPrompt {
)
.child(
div().flex().w_full().items_center().child(
Label::new("Sign in to enable collaboration.")
Label::new(t!("Sign in to enable collaboration."))
.color(Color::Muted)
.size(LabelSize::Small),
),
Expand Down
1 change: 1 addition & 0 deletions crates/collab_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ emojis.workspace = true
futures.workspace = true
fuzzy.workspace = true
gpui.workspace = true
i18n.workspace = true
language.workspace = true
lazy_static.workspace = true
menu.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions crates/collab_ui/src/collab_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use gpui::{
Render, SharedString, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext,
WeakView, WhiteSpace,
};
use i18n::t;
use menu::{Cancel, Confirm, SecondaryConfirm, SelectNext, SelectPrev};
use project::{Fs, Project};
use rpc::{
Expand Down Expand Up @@ -2047,7 +2048,7 @@ impl CollabPanel {
}

fn render_signed_out(&mut self, cx: &mut ViewContext<Self>) -> Div {
let collab_blurb = "Work with your team in realtime with collaborative editing, voice, shared notes and more.";
let collab_blurb = t!("Work with your team in realtime with collaborative editing, voice, shared notes and more.");

v_flex()
.gap_6()
Expand All @@ -2057,7 +2058,7 @@ impl CollabPanel {
v_flex()
.gap_2()
.child(
Button::new("sign_in", "Sign in")
Button::new("sign_in", t!("Sign In"))
.icon_color(Color::Muted)
.icon(IconName::Github)
.icon_position(IconPosition::Start)
Expand All @@ -2076,7 +2077,7 @@ impl CollabPanel {
)
.child(
div().flex().w_full().items_center().child(
Label::new("Sign in to enable collaboration.")
Label::new(t!("Sign in to enable collaboration."))
.color(Color::Muted)
.size(LabelSize::Small),
),
Expand Down
5 changes: 3 additions & 2 deletions crates/collab_ui/src/notification_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use gpui::{
StatefulInteractiveElement, Styled, Task, View, ViewContext, VisualContext, WeakView,
WindowContext,
};
use i18n::t;
use notifications::{NotificationEntry, NotificationEvent, NotificationStore};
use project::Fs;
use rpc::proto;
Expand Down Expand Up @@ -591,7 +592,7 @@ impl Render for NotificationPanel {
.h(rems(ui::Tab::CONTAINER_HEIGHT_IN_REMS))
.border_b_1()
.border_color(cx.theme().colors().border)
.child(Label::new("Notifications"))
.child(Label::new(t!("Notifications")))
.child(Icon::new(IconName::Envelope)),
)
.map(|this| {
Expand All @@ -601,7 +602,7 @@ impl Render for NotificationPanel {
.gap_2()
.p_4()
.child(
Button::new("sign_in_prompt_button", "Sign in")
Button::new("sign_in_prompt_button", t!("Sign In"))
.icon_color(Color::Muted)
.icon(IconName::Github)
.icon_position(IconPosition::Start)
Expand Down
23 changes: 23 additions & 0 deletions crates/i18n/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "i18n"
version = "0.1.0"
description = "Provides I18n backend for other crates in Zed workspace."
edition = "2021"
publish = false
license = "GPL-3.0-or-later"

[lints]
workspace = true

[dependencies]
anyhow.workspace = true
assets.workspace = true
gpui.workspace = true
util.workspace = true
settings.workspace = true
serde.workspace = true
schemars.workspace = true
once_cell.workspace = true

rust-i18n = "3"
serde_yml = "0.0.10"
Loading
Loading