pub fn setup_localization(p: &str) -> Result<(), LocalizationError>Expand description
Sets up localization using the system locale with English fallback. Always loads common strings in addition to utility-specific strings.
This function initializes the localization system based on the system’s locale preferences (via the LANG environment variable) or falls back to English if the system locale cannot be determined or the locale file doesn’t exist. English is always loaded as a fallback.
§Arguments
p- Path to the directory containing localization (.ftl) files
§Returns
Ok(())if initialization succeedsErr(LocalizationError)if initialization fails
§Errors
Returns a LocalizationError if:
- The en-US.ftl file cannot be read (English is required)
- The files contain invalid Fluent syntax
- The bundle cannot be initialized properly
§Examples
use uucore::locale::setup_localization;
// Initialize localization using files in the "locales" directory
// Make sure you have at least an "en-US.ftl" file in this directory
// Other locale files like "fr-FR.ftl" are optional
match setup_localization("./locales") {
Ok(_) => println!("Localization initialized successfully"),
Err(e) => eprintln!("Failed to initialize localization: {e}"),
}