Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jun 3, 2024
1 parent 0cf2de8 commit efd4a5f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 100 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 25 additions & 25 deletions assets/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
About Zed…: "About Zed…"
Check for Updates: "Check for Updates"
Settings: "Settings"
Extensions: "Extensions"
Themes…: "Themes…"
Sign in: "Sign In"
Sign Out: "Sign Out"
Toggle User Menu: "Toggle User Menu"
File: "File"
Edit: "Edit"
New: "New"
New Window: "New Window"
Open…: "Open…"
Open Recent...: "Open Recent..."
Add Folder to Project…: "Add Folder to Project…"
Save: "Save"
Save As…: "Save As…"
Save All: "Save All"
Close Editor: "Close Editor"
Close Window: "Close Window"
Undo: "Undo"
Redo: "Redo"
Cut: "Cut"
Copy: "Copy"
Paste: "Paste"
About Zed…: About Zed…
Check for Updates: Check for Updates
Settings: Settings
Extensions: Extensions
Themes…: Themes…
Sign in: Sign In
Sign Out: Sign Out
Toggle User Menu: Toggle User Menu
File: File
Edit: Edit
New: New
New Window: New Window
Open…: Open…
Open Recent...: Open Recent...
Add Folder to Project…: Add Folder to Project…
Save: Save
Save As…: Save As…
Save All: Save All
Close Editor: Close Editor
Close Window: Close Window
Undo: Undo
Redo: Redo
Cut: Cut
Copy: Copy
Paste: Paste
22 changes: 11 additions & 11 deletions assets/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ Toggle User Menu: 切换用户菜单
File: 文件
Edit: 编辑
New: 新建
New Window: "新建窗口"
New Window: 新建窗口
Open…: 打开…
Open Recent...: 打开最近…
Add Folder to Project…: 添加文件夹到项目…
Save: "保存"
Save As…: "另存为…"
Save All: "全部保存"
Close Editor: "关闭编辑器"
Close Window: "关闭窗口"
Undo: "撤销"
Redo: "重做"
Cut: "剪切"
Copy: "复制"
Paste: "粘贴"
Save: 保存
Save As…: 另存为…
Save All: 全部保存
Close Editor: 关闭编辑器
Close Window: 关闭窗口
Undo: 撤销
Redo: 重做
Cut: 剪切"
Copy: 复制
Paste: 粘贴
1 change: 1 addition & 0 deletions crates/i18n/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ gpui.workspace = true
settings.workspace = true
serde.workspace = true
schemars.workspace = true
once_cell.workspace = true

serde_yaml = "0.9"
24 changes: 16 additions & 8 deletions crates/i18n/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
use ::settings::Settings;
use ::settings::SettingsStore;
use gpui::AppContext;
use once_cell::sync::Lazy;
use settings::I18nSettings;
use std::collections::HashMap;
use util::ResultExt;

mod settings;

rust_i18n::i18n!(fallback = "en");
static BACKEND_DATA: Lazy<BackendData> = Lazy::new(BackendData::init);

type Translations = HashMap<String, HashMap<String, String>>;

pub struct Backend {
pub struct BackendData {
trs: Translations,
}

impl Backend {
pub fn reload() -> Self {
impl BackendData {
pub fn init() -> Self {
let mut trs = Translations::default();

// Load all translations from assets/locales/*.yml
Expand All @@ -42,15 +43,22 @@ impl Backend {

Self { trs }
}

pub fn available_locales(&self) -> impl Iterator<Item = &str> {
self.trs.keys().map(|s| s.as_str())
}
}

#[derive(Default)]
pub struct Backend {}

impl rust_i18n::Backend for Backend {
fn available_locales(&self) -> Vec<&str> {
self.trs.keys().map(|s| s.as_str()).collect()
BACKEND_DATA.trs.keys().map(|s| s.as_str()).collect()
}

fn translate<'a>(&'a self, locale: &str, key: &str) -> Option<&str> {
if let Some(trs) = self.trs.get(locale) {
fn translate(&self, locale: &str, key: &str) -> Option<&str> {
if let Some(trs) = BACKEND_DATA.trs.get(locale) {
trs.get(key).map(|s| s.as_str())
} else {
None
Expand All @@ -62,7 +70,7 @@ impl rust_i18n::Backend for Backend {
#[macro_export]
macro_rules! init {
() => {
rust_i18n::i18n!(fallback = "en", backend = i18n::Backend::reload());
rust_i18n::i18n!(fallback = "en", backend = i18n::Backend::default());
};
}

Expand Down
4 changes: 2 additions & 2 deletions crates/i18n/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl I18nSettings {
pub fn switch_locale(&mut self, locale: &str, _cx: &mut AppContext) -> Option<String> {
let mut new_locale = None;

if crate::available_locales!().iter().any(|l| *l == locale) {
if crate::BACKEND_DATA.available_locales().any(|l| l == locale) {
self.locale = locale.to_string();
new_locale = Some(locale.to_string());
}
Expand All @@ -36,7 +36,7 @@ impl settings::Settings for I18nSettings {

type FileContent = I18nSettingsContent;

fn load(sources: SettingsSources<Self::FileContent>, cx: &mut AppContext) -> Result<Self> {
fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut AppContext) -> Result<Self> {
let defaults = sources.default;
let mut this = Self {
locale: defaults.locale.clone().unwrap(),
Expand Down
123 changes: 69 additions & 54 deletions crates/zed/src/zed/app_menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ pub fn app_menus() -> Vec<Menu<'static>> {
MenuItem::submenu(Menu {
name: t!("Preferences"),
items: vec![
MenuItem::action("Open Settings", super::OpenSettings),
MenuItem::action("Open Key Bindings", super::OpenKeymap),
MenuItem::action("Open Default Settings", super::OpenDefaultSettings),
MenuItem::action("Open Default Key Bindings", super::OpenDefaultKeymap),
MenuItem::action("Open Local Settings", super::OpenLocalSettings),
MenuItem::action("Select Theme...", theme_selector::Toggle::default()),
MenuItem::action(t!("Open Settings"), super::OpenSettings),
MenuItem::action(t!("Open Key Bindings"), super::OpenKeymap),
MenuItem::action(t!("Open Default Settings"), super::OpenDefaultSettings),
MenuItem::action(t!("Open Default Key Bindings"), super::OpenDefaultKeymap),
MenuItem::action(t!("Open Local Settings"), super::OpenLocalSettings),
MenuItem::action(t!("Select Theme..."), theme_selector::Toggle::default()),
],
}),
MenuItem::action("Extensions", extensions_ui::Extensions),
MenuItem::action("Install CLI", install_cli::Install),
MenuItem::action(t!("Extensions"), extensions_ui::Extensions),
MenuItem::action(t!("Install CLI"), install_cli::Install),
MenuItem::separator(),
MenuItem::action("Hide Zed", super::Hide),
MenuItem::action("Hide Others", super::HideOthers),
MenuItem::action("Show All", super::ShowAll),
MenuItem::action("Quit", Quit),
MenuItem::action(t!("Hide Zed"), super::Hide),
MenuItem::action(t!("Hide Others"), super::HideOthers),
MenuItem::action(t!("Show All"), super::ShowAll),
MenuItem::action(t!("Quit"), Quit),
],
},
Menu {
Expand Down Expand Up @@ -85,91 +85,106 @@ pub fn app_menus() -> Vec<Menu<'static>> {
editor::actions::SelectAll,
OsAction::SelectAll,
),
MenuItem::action("Expand Selection", editor::actions::SelectLargerSyntaxNode),
MenuItem::action("Shrink Selection", editor::actions::SelectSmallerSyntaxNode),
MenuItem::action(
t!("Expand Selection"),
editor::actions::SelectLargerSyntaxNode,
),
MenuItem::action(
t!("Shrink Selection"),
editor::actions::SelectSmallerSyntaxNode,
),
MenuItem::separator(),
MenuItem::action("Add Cursor Above", editor::actions::AddSelectionAbove),
MenuItem::action("Add Cursor Below", editor::actions::AddSelectionBelow),
MenuItem::action(t!("Add Cursor Above"), editor::actions::AddSelectionAbove),
MenuItem::action(t!("Add Cursor Below"), editor::actions::AddSelectionBelow),
MenuItem::action(
"Select Next Occurrence",
t!("Select Next Occurrence"),
editor::actions::SelectNext {
replace_newest: false,
},
),
MenuItem::separator(),
MenuItem::action("Move Line Up", editor::actions::MoveLineUp),
MenuItem::action("Move Line Down", editor::actions::MoveLineDown),
MenuItem::action("Duplicate Selection", editor::actions::DuplicateLineDown),
MenuItem::action(t!("Move Line Up"), editor::actions::MoveLineUp),
MenuItem::action(t!("Move Line Down"), editor::actions::MoveLineDown),
MenuItem::action(
t!("Duplicate Selection"),
editor::actions::DuplicateLineDown,
),
],
},
Menu {
name: t!("View"),
items: vec![
MenuItem::action("Zoom In", super::IncreaseBufferFontSize),
MenuItem::action("Zoom Out", super::DecreaseBufferFontSize),
MenuItem::action("Reset Zoom", super::ResetBufferFontSize),
MenuItem::separator(),
MenuItem::action("Toggle Left Dock", workspace::ToggleLeftDock),
MenuItem::action("Toggle Right Dock", workspace::ToggleRightDock),
MenuItem::action("Toggle Bottom Dock", workspace::ToggleBottomDock),
MenuItem::action("Close All Docks", workspace::CloseAllDocks),
MenuItem::action(t!("Zoom In"), super::IncreaseBufferFontSize),
MenuItem::action(t!("Zoom Out"), super::DecreaseBufferFontSize),
MenuItem::action(t!("Reset Zoom"), super::ResetBufferFontSize),
MenuItem::separator(),
MenuItem::action(t!("Toggle Left Dock"), workspace::ToggleLeftDock),
MenuItem::action(t!("Toggle Right Dock"), workspace::ToggleRightDock),
MenuItem::action(t!("Toggle Bottom Dock"), workspace::ToggleBottomDock),
MenuItem::action(t!("Close All Docks"), workspace::CloseAllDocks),
MenuItem::submenu(Menu {
name: t!("Editor Layout"),
items: vec![
MenuItem::action("Split Up", workspace::SplitUp),
MenuItem::action("Split Down", workspace::SplitDown),
MenuItem::action("Split Left", workspace::SplitLeft),
MenuItem::action("Split Right", workspace::SplitRight),
MenuItem::action(t!("Split Up"), workspace::SplitUp),
MenuItem::action(t!("Split Down"), workspace::SplitDown),
MenuItem::action(t!("Split Left"), workspace::SplitLeft),
MenuItem::action(t!("Split Right"), workspace::SplitRight),
],
}),
MenuItem::separator(),
MenuItem::action("Project Panel", project_panel::ToggleFocus),
MenuItem::action("Collab Panel", collab_panel::ToggleFocus),
MenuItem::action("Terminal Panel", terminal_panel::ToggleFocus),
MenuItem::action(t!("Project Panel"), project_panel::ToggleFocus),
MenuItem::action(t!("Collab Panel"), collab_panel::ToggleFocus),
MenuItem::action(t!("Terminal Panel"), terminal_panel::ToggleFocus),
MenuItem::separator(),
MenuItem::action("Diagnostics", diagnostics::Deploy),
MenuItem::action(t!("Diagnostics"), diagnostics::Deploy),
MenuItem::separator(),
],
},
Menu {
name: t!("Go"),
items: vec![
MenuItem::action("Back", workspace::GoBack),
MenuItem::action("Forward", workspace::GoForward),
MenuItem::action(t!("Back"), workspace::GoBack),
MenuItem::action(t!("Forward"), workspace::GoForward),
MenuItem::separator(),
MenuItem::action("Command Palette...", command_palette::Toggle),
MenuItem::action(t!("Command Palette..."), command_palette::Toggle),
MenuItem::separator(),
MenuItem::action("Go to File...", file_finder::Toggle::default()),
MenuItem::action(t!("Go to File..."), file_finder::Toggle::default()),
// MenuItem::action("Go to Symbol in Project", project_symbols::Toggle),
MenuItem::action("Go to Symbol in Editor...", outline::Toggle),
MenuItem::action("Go to Line/Column...", go_to_line::Toggle),
MenuItem::action(t!("Go to Symbol in Editor..."), outline::Toggle),
MenuItem::action(t!("Go to Line/Column..."), go_to_line::Toggle),
MenuItem::separator(),
MenuItem::action("Go to Definition", editor::actions::GoToDefinition),
MenuItem::action("Go to Type Definition", editor::actions::GoToTypeDefinition),
MenuItem::action("Find All References", editor::actions::FindAllReferences),
MenuItem::action(t!("Go to Definition"), editor::actions::GoToDefinition),
MenuItem::action(
t!("Go to Type Definition"),
editor::actions::GoToTypeDefinition,
),
MenuItem::action(
t!("Find All References"),
editor::actions::FindAllReferences,
),
MenuItem::separator(),
MenuItem::action("Next Problem", editor::actions::GoToDiagnostic),
MenuItem::action("Previous Problem", editor::actions::GoToPrevDiagnostic),
MenuItem::action(t!("Next Problem"), editor::actions::GoToDiagnostic),
MenuItem::action(t!("Previous Problem"), editor::actions::GoToPrevDiagnostic),
],
},
Menu {
name: t!("Window"),
items: vec![
MenuItem::action("Minimize", super::Minimize),
MenuItem::action("Zoom", super::Zoom),
MenuItem::action(t!("Minimize"), super::Minimize),
MenuItem::action(t!("Zoom"), super::Zoom),
MenuItem::separator(),
],
},
Menu {
name: t!("Help"),
items: vec![
MenuItem::action("View Telemetry", super::OpenTelemetryLog),
MenuItem::action("View Dependency Licenses", super::OpenLicenses),
MenuItem::action("Show Welcome", workspace::Welcome),
MenuItem::action("Give Feedback...", feedback::GiveFeedback),
MenuItem::action(t!("View Telemetry"), super::OpenTelemetryLog),
MenuItem::action(t!("View Dependency Licenses"), super::OpenLicenses),
MenuItem::action(t!("Show Welcome"), workspace::Welcome),
MenuItem::action(t!("Give Feedback..."), feedback::GiveFeedback),
MenuItem::separator(),
MenuItem::action(
"Documentation",
t!("Documentation"),
super::OpenBrowser {
url: "https://zed.dev/docs".into(),
},
Expand Down

0 comments on commit efd4a5f

Please sign in to comment.