summaryrefslogtreecommitdiffstats
path: root/src/output/details.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-02-10 18:14:56 +0000
committerBen S <ogham@bsago.me>2015-02-10 18:14:56 +0000
commit2906b8676a9b3e76014d65a9940bf576ce1e4852 (patch)
tree7a27cd4a2d18ef53c4a805ea7707b0dfa5b12286 /src/output/details.rs
parente39a20a5d4e522157f6ab09a2d90ef8cd7f46ee3 (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/details.rs')
-rw-r--r--src/output/details.rs25
1 files changed, 23 insertions, 2 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(),
+ }
+ }
+}