/// Creates a new translator for a given locale, passing in translations in FTL syntax form.
Creates a new translator for a given locale, passing in translations in FTL syntax form.
Creates a new translator for a given locale passing in translations in FTL syntax form .
pub fn new(locale: String, ftl_string: String) -> Result<Self, TranslatorError> {
        let resource = FluentResource::try_new(ftl_string)
            // If this errors, we get it still and a vector of errors (wtf.)
            .map_err(|(_, errs)| TranslatorError::TranslationsStrSerFailed {
                locale: locale.clone(),
                source: errs
                    .iter()
                    .map(|e| e.to_string())
                    .collect::<String>()
                    .into(),
            })?;
        let lang_id: LanguageIdentifier =
            locale.parse().map_err(|err: LanguageIdentifierError| {
                TranslatorError::InvalidLocale {
                    locale: locale.clone(),
                    source: Box::new(err),
                }
            })?;
        let mut bundle = FluentBundle::new_concurrent(vec![lang_id]);
        bundle.add_resource(resource).map_err(|errs| {
            TranslatorError::TranslationsStrSerFailed {
                locale: locale.clone(),
                source: errs
                    .iter()
                    .map(|e| e.to_string())
                    .collect::<String>()
                    .into(),
            }
        })?;
        let bundle = Arc::new(bundle);
        Ok(Self { bundle, locale })
    }
pub fn new ( locale : String , ftl_string : String ) -> Result < Self , TranslatorError > { let resource = FluentResource :: try_new ( ftl_string ) // If this errors, we get it still and a vector of errors (wtf.) . map_err ( | ( _ , errs ) | TranslatorError :: TranslationsStrSerFailed { locale : locale . clone ( ) , source : errs . iter ( ) . map ( | e | e . to_string ( ) ) . collect :: < String > ( ) . into ( ) , } ) ? ; let lang_id : LanguageIdentifier = locale . parse ( ) . map_err ( | err : LanguageIdentifierError | { TranslatorError :: InvalidLocale { locale : locale . clone ( ) , source : Box :: new ( err ) , } } ) ? ; let mut bundle = FluentBundle :: new_concurrent ( vec ! [ lang_id ] ) ; bundle . add_resource ( resource ) . map_err ( | errs | { TranslatorError :: TranslationsStrSerFailed { locale : locale . clone ( ) , source : errs . iter ( ) . map ( | e | e . to_string ( ) ) . collect :: < String > ( ) . into ( ) , } } ) ? ; let bundle = Arc :: new ( bundle ) ; Ok ( Self { bundle , locale } ) }
Creates a new translator for a given locale, passing in translations in FTL syntax form.
Creates a new translator for a given locale passing in translations in FTL syntax form .
locale
String
ftl_string
String