def get_path_from_request( request: 'HttpRequest', full_path: bool = SEO_USE_URL_FULL_PATH ) -> str: """ Return current path from request, excluding language code """ if full_path: path = request.get_full_path() else: path = request.path regex_match = language_code_prefix_re.match(path) if regex_match: lang_code = regex_match.group(1) languages = [ language_tuple[0] for language_tuple in settings.LANGUAGES ] if lang_code in languages: path = path[1 + len(lang_code):] if not path.startswith('/'): path = '/' + path return path
def remove_lang_from_path(self, path): no_lang_tag_path = path regex_match = language_code_prefix_re.match(path) if regex_match: lang_code = regex_match.group(1) no_lang_tag_path = path[1 + len(lang_code):] if not no_lang_tag_path.startswith('/'): no_lang_tag_path = '/' + no_lang_tag_path return no_lang_tag_path
def remove_lang_from_path(self, path): no_lang_tag_path = path regex_match = language_code_prefix_re.match(path) if regex_match: lang_code = regex_match.group(1) no_lang_tag_path = path[1 + len(lang_code):] if not no_lang_tag_path.startswith('/'): no_lang_tag_path = '/' + no_lang_tag_path return no_lang_tag_path
def get_language_from_path(path): """ Returns the language-code if there is a valid language-code found in the `path`. Based on Django 1.11.16's get_language_from_path from django/utils/translation/trans_real.py, with changes: * Don't accept or pass strict parameter (assume strict=False). * Use our customized get_supported_language_variant(). """ regex_match = language_code_prefix_re.match(path) if not regex_match: return None lang_code = regex_match.group(1) try: return get_supported_language_variant(lang_code) except LookupError: return None
def get_language_from_path(path): """ Returns the language-code if there is a valid language-code found in the `path`. Based on Django 1.11.16's get_language_from_path from django/utils/translation/trans_real.py, with changes: * Don't accept or pass strict parameter (assume strict=False). * Use our customized get_supported_language_variant(). """ regex_match = language_code_prefix_re.match(path) if not regex_match: return None lang_code = regex_match.group(1) try: return get_supported_language_variant(lang_code) except LookupError: return None
def strip_language_from_path(path: str) -> str: """ Return current path from request, excluding language code """ regex_match = language_code_prefix_re.match(path) if regex_match: lang_code = regex_match.group(1) languages = [ language_tuple[0] for language_tuple in settings.LANGUAGES ] if lang_code in languages: path = path[1 + len(lang_code):] if not path.startswith('/'): path = '/' + path return path
def get_language_from_path(path): """ Returns the language-code if there is a valid language-code found in the `path`. If `strict` is False (the default), the function will look for an alternative country-specific variant when the currently checked is not found. Based on Django 1.8.19's get_language_from_path from django/utils/translation/trans_real.py, with changes: * Don't accept or pass strict parameter (assume strict=False). """ regex_match = language_code_prefix_re.match(path) if not regex_match: return None lang_code = regex_match.group(1) try: return get_supported_language_variant(lang_code) except LookupError: return None