pub fn new(resources: Vec<String>, base_dir: &str) -> Self {
        fn get_available_locales(base_dir: &str) -> Result<Vec<LanguageIdentifier>, io::Error> {
            let mut locales = vec![];

            let res_dir = fs::read_dir(base_dir)?;
            for entry in res_dir.flatten() {
                let path = entry.path();
                if path.is_dir() {
                    if let Some(name) = path.file_name() {
                        if let Some(name) = name.to_str() {
                            let langid: LanguageIdentifier = name.parse().expect("Parsing failed.");
                            locales.push(langid);
                        }
                    }
                }
            }
            Ok(locales)
        }

        let default_locale: LanguageIdentifier =
            "en-US".parse().expect("failed to parse default locale");
        let current_locale = Application::get_locale()
            .parse()
            .unwrap_or_else(|_| default_locale.clone());
        let locales = get_available_locales(base_dir).unwrap_or_default();
        debug!(
            "available locales {}, current {}",
            PrintLocales(&locales),
            current_locale,
        );
        let mut path_scheme = base_dir.to_string();
        path_scheme.push_str("/{locale}/{res_id}");

        let mut res_mgr = ResourceManager {
            resources: HashMap::new(),
            path_scheme,
            default_locale,
            locales,
        };

        let current_bundle = res_mgr.get_bundle(&current_locale, &resources);

        L10nManager {
            res_mgr,
            resources,
            current_bundle,
            current_locale,
        }
    }
/// Create a new localization manager.
///
/// `resources` is a list of file names that contain strings. `base_dir`
/// is a path to a directory that includes per-locale subdirectories.
///
/// This directory should be of the structure `base_dir/{locale}/{resource}`,
/// where '{locale}' is a valid BCP47 language tag, and {resource} is a `.ftl`
/// included in `resources`.
Create a new localization manager.
`resources` is a list of file names that contain strings. `base_dir`
is a path to a directory that includes per-locale subdirectories.


Create a new localization manager . ` resources ` is a list of file names that contain strings . ` base_dir ` is a path to a directory that includes per - locale subdirectories .
pub fn new(resources: Vec<String>, base_dir: &str) -> Self {
        fn get_available_locales(base_dir: &str) -> Result<Vec<LanguageIdentifier>, io::Error> {
            let mut locales = vec![];
            let res_dir = fs::read_dir(base_dir)?;
            for entry in res_dir.flatten() {
                let path = entry.path();
                if path.is_dir() {
                    if let Some(name) = path.file_name() {
                        if let Some(name) = name.to_str() {
                            let langid: LanguageIdentifier = name.parse().expect("Parsing failed.");
                            locales.push(langid);
                        }
                    }
                }
            }
            Ok(locales)
        }
        let default_locale: LanguageIdentifier =
            "en-US".parse().expect("failed to parse default locale");
        let current_locale = Application::get_locale()
            .parse()
            .unwrap_or_else(|_| default_locale.clone());
        let locales = get_available_locales(base_dir).unwrap_or_default();
        debug!(
            "available locales {}, current {}",
            PrintLocales(&locales),
            current_locale,
        );
        let mut path_scheme = base_dir.to_string();
        path_scheme.push_str("/{locale}/{res_id}");
        let mut res_mgr = ResourceManager {
            resources: HashMap::new(),
            path_scheme,
            default_locale,
            locales,
        };
        let current_bundle = res_mgr.get_bundle(&current_locale, &resources);
        L10nManager {
            res_mgr,
            resources,
            current_bundle,
            current_locale,
        }
    }
pub fn new ( resources : Vec < String > , base_dir : & str ) -> Self { fn get_available_locales ( base_dir : & str ) -> Result < Vec < LanguageIdentifier > , io :: Error > { let mut locales = vec ! [ ] ; let res_dir = fs :: read_dir ( base_dir ) ? ; for entry in res_dir . flatten ( ) { let path = entry . path ( ) ; if path . is_dir ( ) { if let Some ( name ) = path . file_name ( ) { if let Some ( name ) = name . to_str ( ) { let langid : LanguageIdentifier = name . parse ( ) . expect ( " " ) ; locales . push ( langid ) ; } } } } Ok ( locales ) } let default_locale : LanguageIdentifier = " " . parse ( ) . expect ( " " ) ; let current_locale = Application :: get_locale ( ) . parse ( ) . unwrap_or_else ( | _ | default_locale . clone ( ) ) ; let locales = get_available_locales ( base_dir ) . unwrap_or_default ( ) ; debug ! ( " " PrintLocales ( locales ) current_locale ) ; let mut path_scheme = base_dir . to_string ( ) ; path_scheme . push_str ( " " ) ; let mut res_mgr = ResourceManager { resources : HashMap :: new ( ) , path_scheme , default_locale , locales , } ; let current_bundle = res_mgr . get_bundle ( & current_locale , & resources ) ; L10nManager { res_mgr , resources , current_bundle , current_locale , } }
Create a new localization manager.
Create a new localization manager .
resources
Vec<String>
base_dir
&str
resources
Vec<String>
base_dir
&str