Commit bf7a9d7d authored by Yusei Tahara's avatar Yusei Tahara

Handle HTTP_ACCEPT_LANGUAGE correctly.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24121 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 849bbc0b
...@@ -57,6 +57,16 @@ installation_status = {'bt5': {'current': 0, ...@@ -57,6 +57,16 @@ installation_status = {'bt5': {'current': 0,
# cookie name to store user's preferred language name # cookie name to store user's preferred language name
LANGUAGE_COOKIE_NAME = 'configurator_user_preferred_language' LANGUAGE_COOKIE_NAME = 'configurator_user_preferred_language'
def getAvailableLanguageFromHttpAcceptLanguage(http_accept_language,
available_language_list,
default='en'):
for language_set in http_accept_language.split(','):
language_tag = language_set.split(';')[0]
language = language_tag.split('-')[0]
if language in available_language_list:
return language
return default
def _isUserAcknowledged(cookiejar): def _isUserAcknowledged(cookiejar):
""" Is user authenticated to remote system through a cookie. """ """ Is user authenticated to remote system through a cookie. """
for cookie in cookiejar: for cookie in cookiejar:
...@@ -445,19 +455,14 @@ class WizardTool(BaseTool): ...@@ -445,19 +455,14 @@ class WizardTool(BaseTool):
if configurator_user_preferred_language is None: if configurator_user_preferred_language is None:
# Find a preferred language from HTTP_ACCEPT_LANGUAGE # Find a preferred language from HTTP_ACCEPT_LANGUAGE
accept_language = REQUEST.get('HTTP_ACCEPT_LANGUAGE', 'en') available_language_list = [i[1] for i in self.WizardTool_getConfigurationLanguageList()]
accept_language_tag = accept_language.split(';')[0].split(',')[0] configurator_user_preferred_language = getAvailableLanguageFromHttpAcceptLanguage(
primary_language = accept_language_tag.split('-')[0] REQUEST.get('HTTP_ACCEPT_LANGUAGE', 'en'),
available_language_list)
configuration_language_list = [language_set[1]
for language_set in self.WizardTool_getConfigurationLanguageList()]
if primary_language in configuration_language_list:
configurator_user_preferred_language = primary_language
if configurator_user_preferred_language is None: if configurator_user_preferred_language is None:
configurator_user_preferred_language = 'en' configurator_user_preferred_language = 'en'
parameter_dict['user_preferred_language'] = configurator_user_preferred_language parameter_dict['user_preferred_language'] = configurator_user_preferred_language
def _updateParameterDictWithFileUpload(self, parameter_dict): def _updateParameterDictWithFileUpload(self, parameter_dict):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment