forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use anyhow::Result; | ||
use gpui::AppContext; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use settings::SettingsSources; | ||
|
||
#[derive(Clone)] | ||
pub struct I18nSettings { | ||
/// Set the UI language, default is "en". | ||
pub locale: String, | ||
} | ||
|
||
impl I18nSettings { | ||
/// Switches to the locale and reloads the translations. | ||
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) { | ||
self.locale = locale.to_string(); | ||
new_locale = Some(locale.to_string()); | ||
} | ||
|
||
new_locale | ||
} | ||
} | ||
/// Settings for rendering text in UI and text buffers. | ||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] | ||
pub struct I18nSettingsContent { | ||
/// The default font size for text in the UI. | ||
#[serde(default)] | ||
pub locale: Option<String>, | ||
} | ||
|
||
impl settings::Settings for I18nSettings { | ||
const KEY: Option<&'static str> = None; | ||
|
||
type FileContent = I18nSettingsContent; | ||
|
||
fn load(sources: SettingsSources<Self::FileContent>, cx: &mut AppContext) -> Result<Self> { | ||
let defaults = sources.default; | ||
let mut this = Self { | ||
locale: defaults.locale.clone().unwrap(), | ||
}; | ||
|
||
for value in sources.user.into_iter().chain(sources.release_channel) { | ||
if let Some(locale) = &value.locale { | ||
this.locale = locale.to_string(); | ||
} | ||
} | ||
|
||
Ok(this) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters