From d994355b5d69e6baaf1705a90b631be1c238f1dc Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Thu, 16 Jun 2022 14:33:21 +0300 Subject: Localize date headings (Issue #54) --- src/ui/task_details.rs | 4 ++-- src/ui/tasks_page.rs | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src/ui') diff --git a/src/ui/task_details.rs b/src/ui/task_details.rs index b8771ac..51dab22 100755 --- a/src/ui/task_details.rs +++ b/src/ui/task_details.rs @@ -206,9 +206,9 @@ impl FurTaskDetails { stop_time_edit.set_text(&stop_time_w_year); let instructions = gtk::Label::new(Some( - &gettext("*Use your local format XX/XX/XX HH:MM:SS"))); + &gettext("*Use the format MM/DD/YY HH:MM:SS"))); if !settings_manager::get_bool("show-seconds") { - instructions.set_text(&gettext("*Use your local format XX/XX/XX HH:MM")); + instructions.set_text(&gettext("*Use the format MM/DD/YY HH:MM")); } instructions.set_visible(false); instructions.add_css_class("error_message"); diff --git a/src/ui/tasks_page.rs b/src/ui/tasks_page.rs index 911b005..192a309 100755 --- a/src/ui/tasks_page.rs +++ b/src/ui/tasks_page.rs @@ -17,9 +17,11 @@ use adw::prelude::{PreferencesGroupExt, PreferencesPageExt}; use adw::subclass::prelude::*; use chrono::{DateTime, Duration, Local}; +use chrono_locale::LocaleDate; use gettextrs::*; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*}; +use std::env; use crate::database::{self, SortOrder, TaskSort}; use crate::settings_manager; @@ -87,6 +89,17 @@ impl FurTasksPage { pub fn build_task_list(&self) { let imp = imp::FurTasksPage::from_instance(&self); + // Get user's locale for date formatting + let locale_env = env::var("LANG"); + let user_locale: String; + if let Err(_) = locale_env { + user_locale = "en_US".to_string(); + } else { + let locale_env = locale_env.unwrap(); + let split_locale: Vec<&str> = locale_env.split(".").collect(); + user_locale = split_locale[0].to_string(); + } + let tasks_list = database::retrieve(TaskSort::StartTime, SortOrder::Descending).unwrap(); let mut uniq_date_list: Vec = Vec::new(); @@ -99,7 +112,7 @@ impl FurTasksPage { for task in tasks_list { let task_clone = task.clone(); let date = DateTime::parse_from_rfc3339(&task.start_time).unwrap(); - let date = date.format("%h %e").to_string(); + let date = date.formatl("%h %e", &user_locale).to_string(); if !uniq_date_list.contains(&date) { // if same_date_list is empty, push "date" to it // if it is not empty, push it to a vec of vecs, and then clear it @@ -135,8 +148,8 @@ impl FurTasksPage { // Create FurTasksGroups for all unique days let now = Local::now(); let yesterday = now - Duration::days(1); - let yesterday = yesterday.format("%h %e").to_string(); - let today = now.format("%h %e").to_string(); + let yesterday = yesterday.formatl("%h %e", &user_locale).to_string(); + let today = now.formatl("%h %e", &user_locale).to_string(); for i in 0..uniq_date_list.len() { let group = FurTasksGroup::new(); if uniq_date_list[i] == today { -- cgit 1.4.1