diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -118,7 +118,7 @@ impl Localiser { } /// Extracts a message from the requested bundle, or from the default one if absent. - pub fn get_message(&self, key: &str, language: &str, args: Option<&FluentArgs>) -> Result<String> { + pub fn try_get_message(&self, key: &str, language: &str, args: Option<&FluentArgs>) -> Result<String> { let bundle = self.bundles.get(language) .or_else(|| self.bundles.get(&self.default_language)) .ok_or(error::Error::GenericError("Failed to get default bundle! This is not supposed to happen!".to_string()))?; @@ -135,4 +135,10 @@ impl Localiser { Err(error::Error::FluentError(err)) } } + + /// Similar to [Localiser::try_get_message], but returns the given key on failure. + pub fn get_message(&self, key: &str, language: &str, args: Option<&FluentArgs>) -> String { + self.try_get_message(key, language, args) + .unwrap_or(key.to_string()) + } } |