def translate_url(self, url, lang): # check that url starts with /en or /fr orig_lang = language.get_language_from_url(url) if orig_lang: new_url = '/' + lang + url[3:] return new_url else: return url
def get_language(self): # parse path and look for potential vanity url url = self.request.url url_obj = urlparse.urlparse(url) path = url_obj.path if path: path_no_slash = path.replace('/','') provider_from_vanity_url = db.get_provider_from_vanity_url(path_no_slash) # parse url and look for potential language url_language = language.get_language_from_url(self.request.url) # look for a prospect prospect = None if self.session.has_key('prospect_id'): prospect_id = self.session['prospect_id'] if prospect_id: prospect = db.get_prospect_from_prospect_id(prospect_id) # set the best language based on information available to us in order of priority # 1. directly in URL # 2. from a logged in user # 3. from a provider's default language (if viewing their profile) # 4. from a prospect's preset language # 5. default system language if url_language: return url_language elif self.get_current_user(): return self.get_current_user().language elif provider_from_vanity_url and provider_from_vanity_url.profile_language: return provider_from_vanity_url.profile_language elif prospect: return prospect.language else: return util.DEFAULT_LANG
def set_language_from_url(self): lang = language.get_language_from_url(self.request.url) self.set_language(lang)