pub struct LanguageDetector { /* private fields */ }Expand description
Detector for identifying language codes from filesystem paths.
Implementations§
Source§impl LanguageDetector
impl LanguageDetector
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new LanguageDetector with default language mappings and patterns.
Initializes internal dictionaries and regex patterns for detection. Do not translate these language codes to English rustdoc!!!
Sourcepub fn detect_from_path(&self, path: &Path) -> Option<LanguageInfo>
pub fn detect_from_path(&self, path: &Path) -> Option<LanguageInfo>
Detect a single language information from the given path.
§Behavior
Attempts detection by directory name first, then by filename pattern.
Sourcepub fn normalize(&self, raw: &str) -> Option<String>
pub fn normalize(&self, raw: &str) -> Option<String>
Normalize a raw language label (typically supplied by an AI model) into the project’s canonical short code.
§Behavior
- The input is lower-cased before lookup.
- Known synonyms are collapsed via the internal
language_codesmap (e.g."english"/"eng"/"EN"→"en","cht"/"繁中"/"traditional-chinese"is matched against the same map; for the latter, only entries the detector knows are mapped). - Unknown but otherwise valid
[A-Za-z0-9_-]{1,16}tokens are passed through verbatim after lower-casing. - Returns
Nonefor empty input.
§Arguments
raw- The raw language label to normalize.
§Returns
Some(code) with the canonical or pass-through code, or None when
the input is empty.
Sourcepub fn get_primary_language(&self, path: &Path) -> Option<String>
pub fn get_primary_language(&self, path: &Path) -> Option<String>
Return the primary detected language code for the provided path.
§Returns
Some(code) if detected, otherwise None.
Sourcepub fn detect_all_languages(&self, path: &Path) -> Vec<LanguageInfo>
pub fn detect_all_languages(&self, path: &Path) -> Vec<LanguageInfo>
Collect all potential language detections from the path.
Sorts results by confidence and removes duplicates by code.