Skip to main content

get_language_from_path

Return the language code if there's a valid language code found in path.

If strict is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found.

def get_language_from_path(
path: string,
strict: boolean = False
) - > string

Return the language code if there's a valid language code found in path.

If strict is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found.

Parameters

NameTypeDescription
pathstringThe URL path or file path string to be inspected for a language code prefix
strictboolean = FalseDetermines whether to strictly match the language code or allow falling back to country-specific variants

Returns

TypeDescription
stringThe validated language code string if a match is found and supported, otherwise None