mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
fix: prefer terminal locale
This commit is contained in:
parent
5a64e6c6c8
commit
73fa43d761
3 changed files with 29 additions and 7 deletions
|
|
@ -64,7 +64,18 @@ fn main() -> Result<(), std::io::Error> {
|
|||
|
||||
fn init() -> Result<shell::Data, args::Status> {
|
||||
let locale = {
|
||||
let sys_locale = get_locale().unwrap_or("en-US".to_string());
|
||||
let sys_locale = {
|
||||
// use terminal locale if available
|
||||
if let Ok(locale) = env::var("LANG") {
|
||||
locale
|
||||
} else if let Ok(locale) = env::var("LC_ALL") {
|
||||
locale
|
||||
} else if let Ok(locale) = env::var("LC_MESSAGES") {
|
||||
locale
|
||||
} else {
|
||||
get_locale().unwrap_or("en-US".to_string())
|
||||
}
|
||||
};
|
||||
if sys_locale.len() < 2 {
|
||||
"en-US".to_string()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use std::env;
|
||||
|
||||
use crate::requests::ai_suggestion;
|
||||
use sys_locale::get_locale;
|
||||
mod buffer;
|
||||
|
|
@ -36,7 +38,18 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
}
|
||||
|
||||
let locale = {
|
||||
let sys_locale = get_locale().unwrap_or("en-US".to_string());
|
||||
let sys_locale = {
|
||||
// use terminal locale if available
|
||||
if let Ok(locale) = env::var("LANG") {
|
||||
locale
|
||||
} else if let Ok(locale) = env::var("LC_ALL") {
|
||||
locale
|
||||
} else if let Ok(locale) = env::var("LC_MESSAGES") {
|
||||
locale
|
||||
} else {
|
||||
get_locale().unwrap_or("en-US".to_string())
|
||||
}
|
||||
};
|
||||
if sys_locale.len() < 2 {
|
||||
"en-US".to_string()
|
||||
} else {
|
||||
|
|
@ -60,7 +73,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
if command.split_whitespace().count() == 1 {
|
||||
return Ok(());
|
||||
}
|
||||
ai_suggestion(&command, &error).await;
|
||||
ai_suggestion(&command, &error, &locale).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use askama::Template;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use sys_locale::get_locale;
|
||||
|
||||
use futures_util::StreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -56,7 +54,7 @@ struct AiPrompt<'a> {
|
|||
set_locale: &'a str,
|
||||
}
|
||||
|
||||
pub async fn ai_suggestion(last_command: &str, error_msg: &str) {
|
||||
pub async fn ai_suggestion(last_command: &str, error_msg: &str, locale: &str) {
|
||||
let conf = match Conf::new() {
|
||||
Some(conf) => conf,
|
||||
None => {
|
||||
|
|
@ -76,7 +74,7 @@ pub async fn ai_suggestion(last_command: &str, error_msg: &str) {
|
|||
|
||||
let user_locale = {
|
||||
let locale = std::env::var("_PR_AI_LOCALE")
|
||||
.unwrap_or_else(|_| get_locale().unwrap_or("en-us".to_string()));
|
||||
.unwrap_or_else(|_| locale.to_string());
|
||||
if locale.len() < 2 {
|
||||
"en-US".to_string()
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue