diff --git a/src/gtfs_reader.rs b/src/gtfs_reader.rs index f35f0fb..a5341ff 100644 --- a/src/gtfs_reader.rs +++ b/src/gtfs_reader.rs @@ -182,6 +182,7 @@ impl RawGtfsReader { pathways: self.read_objs_from_optional_path(p, "pathways.txt"), feed_info: self.read_objs_from_optional_path(p, "feed_info.txt"), read_duration: Utc::now().signed_duration_since(now).num_milliseconds(), + translations: self.read_objs_from_optional_path(p, "translations.txt"), files, source_format: crate::SourceFormat::Directory, sha256: None, @@ -309,6 +310,7 @@ impl RawGtfsReader { } else { Some(Ok(Vec::new())) }, + translations: self.read_optional_file(&file_mapping, &mut archive, "translations.txt"), read_duration: Utc::now().signed_duration_since(now).num_milliseconds(), files, source_format: crate::SourceFormat::Zip, diff --git a/src/objects.rs b/src/objects.rs index 00d59f7..2bda0cc 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -380,6 +380,25 @@ impl fmt::Display for Route { } } +/// Raw structure to hold translations as defined in the GTFS file. See +#[derive(Debug, Serialize, Deserialize, Default)] +pub struct RawTranslation { + /// To which table does the translation apply + pub table_name: String, + /// To which field does the translation apply + pub field_name: String, + /// Language of the translation + pub language: String, + /// Translated value + pub translation: String, + /// The record identifier to translate. For stop_times, it’s the trip_id + pub record_id: Option, + /// Only for stop_times: the stop_sequence + pub record_sub_id: Option, + /// Translate all values that match exactly, instead of specifying individual records + pub field_value: Option, +} + /// A [Trip] where the relationships with other objects have not been checked #[derive(Debug, Serialize, Deserialize, Default)] pub struct RawTrip { diff --git a/src/raw_gtfs.rs b/src/raw_gtfs.rs index 12e6695..ef78053 100644 --- a/src/raw_gtfs.rs +++ b/src/raw_gtfs.rs @@ -45,6 +45,8 @@ pub struct RawGtfs { pub source_format: SourceFormat, /// sha256 sum of the feed pub sha256: Option, + /// All translations, None if the file was absent as it is not mandatory + pub translations: Option, Error>>, } impl RawGtfs { @@ -66,6 +68,10 @@ impl RawGtfs { println!(" Transfers: {}", optional_file_summary(&self.transfers)); println!(" Pathways: {}", optional_file_summary(&self.pathways)); println!(" Feed info: {}", optional_file_summary(&self.feed_info)); + println!( + " Translations: {}", + optional_file_summary(&self.translations) + ); } /// Reads from an url (if starts with http), or a local path (either a directory or zipped file) diff --git a/src/tests.rs b/src/tests.rs index f5d9fbe..42f3b42 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -238,6 +238,17 @@ fn read_pathways() { assert_eq!(None, pathways[0].min_width); } +#[test] +fn read_translations() { + let gtfs = RawGtfs::from_path("fixtures/basic").expect("impossible to read gtfs"); + let translation = >fs.translations.unwrap().unwrap()[0]; + assert_eq!(translation.table_name, "stops"); + assert_eq!(translation.field_name, "stop_name"); + assert_eq!(translation.language, "nl"); + assert_eq!(translation.translation, "Stop Gebied"); + assert_eq!(translation.field_value, None); +} + #[test] fn read_feed_info() { let gtfs = Gtfs::from_path("fixtures/basic").expect("impossible to read gtfs"); @@ -342,7 +353,7 @@ fn display() { #[test] fn path_files() { let gtfs = RawGtfs::from_path("fixtures/basic").expect("impossible to read gtfs"); - assert_eq!(gtfs.files.len(), 13); + assert_eq!(gtfs.files.len(), 14); assert_eq!(gtfs.source_format, SourceFormat::Directory); assert!(gtfs.files.contains(&"agency.txt".to_owned())); }