diff options
author | Ben S <ogham@bsago.me> | 2015-02-10 18:14:56 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-02-10 18:14:56 +0000 |
commit | 2906b8676a9b3e76014d65a9940bf576ce1e4852 (patch) | |
tree | 7a27cd4a2d18ef53c4a805ea7707b0dfa5b12286 /src/output | |
parent | e39a20a5d4e522157f6ab09a2d90ef8cd7f46ee3 (diff) |
Translate month names into the user's locale
This has been mostly done with changes in the datetime crate's suddenly
supporting locales.
It's still important that the user's locale is touched only once and
cached from that point on, so a struct in output::details has been made
public, along with that module. This will change later as that object
gains more and more uses thoughout the codes.
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/details.rs | 25 | ||||
-rw-r--r-- | src/output/mod.rs | 2 |
2 files changed, 24 insertions, 3 deletions
diff --git a/src/output/details.rs b/src/output/details.rs index 973a5e9..93dd4c5 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -25,7 +25,7 @@ impl Details { // padding the fields during output. let columns = self.columns.for_dir(dir); - let locale = locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::default()); + let locale = UserLocale::new(); let mut cache = OSUsers::empty_cache(); let mut table = Vec::new(); self.get_files(&columns[], &mut cache, &locale, &mut table, files, 0); @@ -75,7 +75,7 @@ impl Details { } } - fn get_files(&self, columns: &[Column], cache: &mut OSUsers, locale: &locale::Numeric, dest: &mut Vec<Row>, src: &[File], depth: usize) { + fn get_files(&self, columns: &[Column], cache: &mut OSUsers, locale: &UserLocale, dest: &mut Vec<Row>, src: &[File], depth: usize) { for (index, file) in src.iter().enumerate() { let row = Row { @@ -106,3 +106,24 @@ struct Row { pub last: bool, pub children: bool, } + +pub struct UserLocale { + pub time: locale::Time, + pub numeric: locale::Numeric, +} + +impl UserLocale { + pub fn new() -> UserLocale { + UserLocale { + time: locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::default()), + numeric: locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::default()), + } + } + + pub fn default() -> UserLocale { + UserLocale { + time: locale::Time::default(), + numeric: locale::Numeric::default(), + } + } +} diff --git a/src/output/mod.rs b/src/output/mod.rs index 054e6bf..22b8726 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -1,5 +1,5 @@ mod grid; -mod details; +pub mod details; mod lines; pub use self::grid::Grid; |