Skip to content

Commit

Permalink
Fallback to default when requested language is missing, rather than p…
Browse files Browse the repository at this point in the history
…anicking (#16)
  • Loading branch information
benjaminwinger authored Jul 21, 2020
1 parent f4af159 commit 0264258
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 6 additions & 4 deletions templates/src/loader/arc_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ impl super::Loader for ArcLoader {
text_id: &str,
args: Option<&HashMap<String, FluentValue>>,
) -> String {
for l in self.fallbacks.get(lang).expect("language not found") {
if let Some(val) = self.lookup_single_language(l, text_id, args) {
return val;
if let Some(fallbacks) = self.fallbacks.get(lang) {
for l in fallbacks {
if let Some(val) = self.lookup_single_language(l, text_id, args) {
return val;
}
}
}
if *lang != self.fallback {
Expand Down Expand Up @@ -168,7 +170,7 @@ impl ArcLoader {
None
}
} else {
panic!("Unknown language {}", lang)
None
}
}
}
16 changes: 10 additions & 6 deletions templates/src/loader/static_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ impl StaticLoader {
text_id: &str,
args: Option<&HashMap<String, FluentValue>>,
) -> Option<String> {
for l in self.fallbacks.get(lang).expect("language not found") {
if let Some(val) = self.lookup_single_language(l, text_id, args) {
return Some(val);
if let Some(fallbacks) = self.fallbacks.get(lang) {
for l in fallbacks {
if let Some(val) = self.lookup_single_language(l, text_id, args) {
return Some(val);
}
}
}

Expand All @@ -87,9 +89,11 @@ impl super::Loader for StaticLoader {
text_id: &str,
args: Option<&HashMap<String, FluentValue>>,
) -> String {
for l in self.fallbacks.get(lang).expect("language not found") {
if let Some(val) = self.lookup_single_language(l, text_id, args) {
return val;
if let Some(fallbacks) = self.fallbacks.get(lang) {
for l in fallbacks {
if let Some(val) = self.lookup_single_language(l, text_id, args) {
return val;
}
}
}
if *lang != self.fallback {
Expand Down

0 comments on commit 0264258

Please # to comment.