Removes unnecessary complexity that was creating error cases, allowing localize()
and message_for_locale()
to be infallible. The std::io::Write
writer
was removed as it just ended up causing more difficulty than what was really worth dealing with, for little (if any) actual gains.
QJC4IQITOQP65AFLA5CMH2EXHB6B3SOLW2XBV72U5ZQU2KOR2EIAC
7X4MEZJUMLYYIBV7ANLADELOZ7I7AJ5CKFAR35CJ2SBZDDVJFZOQC
MWN4CAOZNFHFCZ67KA3T27CI6NE3DDXKYX7S5K7QTEWMWUPDHSTQC
U2PHMYPDFQQYTPDVVJLWDJM5G45ILXLWDDDTZVV2NBOSCED323MQC
JUV7C6ET4ZQJNLO7B4JB7XMLV2YUBZB4ARJHN4JEPHDGGBWGLEVAC
BAH2JCJPTDXAE6XGSLIPBQZU4GQY65HI66Q4XTFNL65MV6VSNF2QC
MABGENI7CW5F5D3BFUJ7BS2H7XPYG4F3UMWGDPFFSMCCZKUUDLDQC
YZ6PVVQCLWYRFM33CH6BDB7U6BSP5PM5LH3FMKRXV3BH5KCRFM4AC
CESJ4CTO26X4GBZBPXRXLOJT3JQJOGFN5EJSNAAZELNQRZF7QSYAC
LU6IFZFGPIKF3CBWZWITWVBSCYWF7Q4UXJDXVRWZ4XV7PKE5RSTQC
3NMKD6I57ONAGHEN4PZIAV2KPYESVR4JL3DTWSHXKCMVJBEQ4GIQC
7M4UI3TWQIAA333GQ577HDWDWZPSZKWCYG556L6SBRLB6SZDQYPAC
F5LG7WENUUDRSCTDMA4M6BAC5RWTGQO45C4ZEBZDX6FHCTTHBVGQC
NO3PDO7PY7J3WPADNCS5VD6HKFY63E23I3SDR4DHXNVQJTG27RAAC
XGNME3WRU3MJDTFHUFJYARLVXWBZIH5ODBOIIFTXHNCBTZQH2R7QC
7JPOCQEISAIOD7LV4JYBE6NNUWUKKNE73MEPQYTIZ7PP44ZAD2RAC
O77KA6C4UJGZXVGPEA7WCRQH6XYQJPWETSPDXI3VOKOSRQND7JEQC
5TEX4MNUC4LDDRMNEOVCFNUUEZAGUXMKO3OIEQFXWRQKXSHY2NRQC
C6W7N6N57UCNHEV55HEZ3G7WN2ZOBGMFBB5M5ZPDB2HNNHHTOPBQC
BFL2Y7GN6NBXXNAUSD4M6T6CIVQ2OLERPE2CAFSLRF377WFFTVCQC
IRW6JACS3KVVA6HW5SBNBOHOQ2WRBHYGDND3FUWJYKJC7ZMOAVOQC
WWDZWJTRJWSLVFMQFHS7JMDPK5VNDIQ6IHSMES7BVKYHZY6WRYKAC
HHJDRLLNN36UNIA7STAXEEVBCEMPJNB7SJQOS3TJLLYN4AEZ4MHQC
GJMBIJOE47X7DKZDHIY6VQ2ISC52XAVAV46L6PJQZTV7L7DDSWOAC
) -> Result<Self, LocalizationError> {
let confirmation_text = confirmation.localize()?;
let mismatch_error_text = mismatch_error.localize()?;
) -> Self {
let confirmation_text = confirmation.localize();
let mismatch_error_text = mismatch_error.localize();
pub fn with_prompt<L: Localize>(
mut self,
prompt: L,
) -> Result<Self, LocalizationError> {
let localized_text = prompt.localize()?;
pub fn with_prompt<L: fluent_embed::Localize>(mut self, prompt: L) -> Self {
let localized_text = prompt.localize();
pub fn with_default<L: Localize>(mut self, default: L) -> Result<Self, LocalizationError> {
let localized_text = default.localize()?;
pub fn with_default<L: Localize>(mut self, default: L) -> Self {
let localized_text = default.localize();
pub fn with_message<L: Localize>(mut self, message: L) -> Result<Self, LocalizationError> {
let localized_text = message.localize()?;
pub fn with_message<L: Localize>(mut self, message: L) -> Self {
let localized_text = message.localize();
fn message_for_locale<W: std::io::Write>(
&self,
writer: &mut W,
locale: &LanguageIdentifier,
) -> Result<(), LocalizationError> {
fn message_for_locale(&self, locale: &LanguageIdentifier) -> String {
writer.write_all(formatted_text.to_string().as_bytes())?;
writer.flush()?;
Ok(())
formatted_text.to_string()
fn message_for_locale<W: std::io::Write>(
&self,
writer: &mut W,
_locale: &LanguageIdentifier,
) -> Result<(), crate::LocalizationError> {
writer.write_all(self.as_bytes())?;
Ok(())
fn message_for_locale(&self, _locale: &LanguageIdentifier) -> String {
self.to_string()
#[derive(thiserror::Error, Debug)]
pub enum LocalizationError {
#[error("unable to write localized output")]
IO(#[from] std::io::Error),
#[error("unable to retrieve system locales")]
RetrievalError(env_preferences::LocaleError),
#[error("unable to parse localized output as a UTF-8 string. This is a bug in `fluent_embed`.")]
InvalidOutput(#[from] std::string::FromUtf8Error),
}
fn message_for_locale<W: std::io::Write>(
&self,
writer: &mut W,
locale: &LanguageIdentifier,
) -> Result<(), LocalizationError>;
fn message_for_locale(&self, locale: &LanguageIdentifier) -> String;
fn localize(&self) -> Result<String, LocalizationError> {
let system_locales = env_preferences::get_locales_lossy()
.map_err(|error| LocalizationError::RetrievalError(error))?;
fn localize(&self) -> String {
let system_locales =
env_preferences::get_locales_lossy().unwrap_or(vec![Self::CANONICAL_LOCALE.into()]);