## -*- coding: utf-8 -*- ## ## ## Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. ## <%! import os.path import pkg.server.api as api import pkg.server.api_errors as api_errors CLIENT_API_VERSION = 12 %>\ <%page args="g_vars"/>\ <% base = g_vars["base"] http_depot = g_vars["http_depot"] config = api.ConfigInterface(CLIENT_API_VERSION, base) request = api.RequestInterface(CLIENT_API_VERSION, base) # XXX default language if one can't be automatically determined, # where to set this? dlang = "en" # First, get the list of desired languages from the request. rlangs = request.get_accepted_languages() # Second, check each language name (which should either be an ISO # 639(.1/.2) code or an l10n simple name) to see if a directory of # content exists for it. for rl in rlangs: if os.path.exists(os.path.join(config.web_root, rl)): dlang = rl break # Third, determine if we need to redirect the user to a particular # page. rpath = request.path_info.strip("/") pub = g_vars["pub"] if pub: # Ignore publisher component of path. rpath = rpath.replace(pub, "").strip("/") prefix = "" if rpath == "": # Because the redirect is relative if the original request # didn't end with a '/', special care has to be taken for # this particular case. if pub and not request.path_info.endswith("/"): prefix = pub + "/" rpath = "index.shtml" if http_depot: prefix = http_depot # Finally, redirect the client to the content appropriate for their # language and region. raise api_errors.RedirectException("%s%s/%s" % (prefix, dlang, rpath)) %>\