Localized date strings
Fixes some of #256 This patch also cleans up the `icu` dependencies from my last PR. I added all of `icu` as a dependency last time because I assumed it would be needed for this fix. However, `chrono` supports localization and `icu` seemed harder to use anyway.
This commit is contained in:
parent
eba72e131a
commit
748d53fdbe
4 changed files with 27 additions and 313 deletions
|
|
@ -6,7 +6,7 @@ use i18n_embed::{
|
|||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||
DefaultLocalizer, LanguageLoader, Localizer,
|
||||
};
|
||||
use icu::collator::{Collator, CollatorOptions, Numeric};
|
||||
use icu_collator::{Collator, CollatorOptions, Numeric};
|
||||
use icu_provider::DataLocale;
|
||||
use once_cell::sync::Lazy;
|
||||
use rust_embed::RustEmbed;
|
||||
|
|
@ -40,6 +40,19 @@ pub static LANGUAGE_SORTER: Lazy<Collator> = Lazy::new(|| {
|
|||
.expect("Creating a collator from the system's current language, the fallback language, or American English should succeed")
|
||||
});
|
||||
|
||||
pub static LANGUAGE_CHRONO: Lazy<chrono::Locale> = Lazy::new(|| {
|
||||
std::env::var("LANG")
|
||||
.ok()
|
||||
.and_then(|locale_full| {
|
||||
// Split LANG because it may be set to a locale such as en_US.UTF8
|
||||
locale_full
|
||||
.split('.')
|
||||
.next()
|
||||
.and_then(|locale| chrono::Locale::from_str(locale).ok())
|
||||
})
|
||||
.unwrap_or(chrono::Locale::en_US)
|
||||
});
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fl {
|
||||
($message_id:literal) => {{
|
||||
|
|
|
|||
16
src/tab.rs
16
src/tab.rs
|
|
@ -47,7 +47,7 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste};
|
||||
use crate::localize::LANGUAGE_SORTER;
|
||||
use crate::localize::{LANGUAGE_CHRONO, LANGUAGE_SORTER};
|
||||
use crate::{
|
||||
app::{self, Action},
|
||||
config::{IconSizes, TabConfig, ICON_SCALE_MAX, ICON_SIZE_GRID},
|
||||
|
|
@ -806,21 +806,24 @@ impl Item {
|
|||
if let Ok(time) = metadata.created() {
|
||||
column = column.push(widget::text(format!(
|
||||
"Created: {}",
|
||||
chrono::DateTime::<chrono::Local>::from(time).format(TIME_FORMAT)
|
||||
chrono::DateTime::<chrono::Local>::from(time)
|
||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||
)));
|
||||
}
|
||||
|
||||
if let Ok(time) = metadata.modified() {
|
||||
column = column.push(widget::text(format!(
|
||||
"Modified: {}",
|
||||
chrono::DateTime::<chrono::Local>::from(time).format(TIME_FORMAT)
|
||||
chrono::DateTime::<chrono::Local>::from(time)
|
||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||
)));
|
||||
}
|
||||
|
||||
if let Ok(time) = metadata.accessed() {
|
||||
column = column.push(widget::text(format!(
|
||||
"Accessed: {}",
|
||||
chrono::DateTime::<chrono::Local>::from(time).format(TIME_FORMAT)
|
||||
chrono::DateTime::<chrono::Local>::from(time)
|
||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
|
@ -860,7 +863,8 @@ impl Item {
|
|||
if let Ok(time) = metadata.modified() {
|
||||
column = column.push(widget::text(format!(
|
||||
"Last modified: {}",
|
||||
chrono::DateTime::<chrono::Local>::from(time).format(TIME_FORMAT)
|
||||
chrono::DateTime::<chrono::Local>::from(time)
|
||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
|
@ -2564,7 +2568,7 @@ impl Tab {
|
|||
let modified_text = match &item.metadata {
|
||||
ItemMetadata::Path { metadata, .. } => match metadata.modified() {
|
||||
Ok(time) => chrono::DateTime::<chrono::Local>::from(time)
|
||||
.format(TIME_FORMAT)
|
||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||
.to_string(),
|
||||
Err(_) => String::new(),
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue