diff options
-rw-r--r-- | askbot/conf/skin_general_settings.py | 38 | ||||
-rw-r--r-- | askbot/feed.py | 59 | ||||
-rw-r--r-- | askbot/middleware/locale.py | 26 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py | 1 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py.mustache | 1 | ||||
-rw-r--r-- | askbot/skins/default/templates/main_page/tab_bar.html | 4 | ||||
-rw-r--r-- | askbot/skins/utils.py | 14 |
7 files changed, 111 insertions, 32 deletions
diff --git a/askbot/conf/skin_general_settings.py b/askbot/conf/skin_general_settings.py index ccecdaba..6abee90a 100644 --- a/askbot/conf/skin_general_settings.py +++ b/askbot/conf/skin_general_settings.py @@ -30,6 +30,40 @@ settings.register( ) ) +LANGUAGE_CHOICES = ( + ('en', _("English")), + ('es', _("Spanish")), + ('ca', _("Catalan")), + ('de', _("German")), + ('el', _("Greek")), + ('fi', _("Finnish")), + ('fr', _("French")), + ('hi', _("Hindi")), + ('hu', _("Hungarian")), + ('it', _("Italian")), + ('ja', _("Japanese")), + ('ko', _("Korean")), + ('pt', _("Portuguese")), + ('pt_BR', _("Brazilian Portuguese")), + ('ro', _("Romanian")), + ('ru', _("Russian")), + ('sr', _("Serbian")), + ('tr', _("Turkish")), + ('vi', _("Vietnamese")), + ('zh_CN', _("Chinese")), + ('zh_TW', _("Chinese (Taiwan)")), + ) + +settings.register( + values.StringValue( + GENERAL_SKIN_SETTINGS, + 'ASKBOT_LANGUAGE', + default = 'en', + choices = LANGUAGE_CHOICES, + description = _('Select Language'), + ) +) + settings.register( values.BooleanValue( GENERAL_SKIN_SETTINGS, @@ -198,7 +232,7 @@ settings.register( description = _('Apply custom style sheet (CSS)'), help_text = _( 'Check if you want to change appearance ' - 'of your form by adding custom style sheet rules ' + 'of your form by adding custom style sheet rules ' '(please see the next item)' ), default = False @@ -214,7 +248,7 @@ settings.register( '<strong>To use this function</strong>, check ' '"Apply custom style sheet" option above. ' 'The CSS rules added in this window will be applied ' - 'after the default style sheet rules. ' + 'after the default style sheet rules. ' 'The custom style sheet will be served dynamically at ' 'url "<forum url>/custom.css", where ' 'the "<forum url> part depends (default is ' diff --git a/askbot/feed.py b/askbot/feed.py index c1933afe..776aad5e 100644 --- a/askbot/feed.py +++ b/askbot/feed.py @@ -25,20 +25,29 @@ from askbot.conf import settings as askbot_settings class RssIndividualQuestionFeed(Feed): """rss feed class for particular questions """ - title = askbot_settings.APP_TITLE + _(' - ')+ _('Individual question feed') - link = askbot_settings.APP_URL - description = askbot_settings.APP_DESCRIPTION - copyright = askbot_settings.APP_COPYRIGHT + + def title(self): + return askbot_settings.APP_TITLE + _(' - ') + \ + _('Individual question feed') + + def feed_copyright(self): + return askbot_settings.APP_COPYRIGHT + + def description(self): + return askbot_settings.APP_DESCRIPTION def get_object(self, bits): if len(bits) != 1: raise ObjectDoesNotExist return Post.objects.get_questions().get(id__exact = bits[0]) - + def item_link(self, item): """get full url to the item """ - return self.link + item.get_absolute_url() + return askbot_settings.APP_URL + item.get_absolute_url() + + def link(self): + return askbot_settings.APP_URL def item_pubdate(self, item): """get date of creation for the item @@ -56,7 +65,7 @@ class RssIndividualQuestionFeed(Feed): chain_elements.append( Post.objects.get_comments().filter(parent=item) ) - + answers = Post.objects.get_answers().filter(thread = item.thread) for answer in answers: chain_elements.append([answer,]) @@ -65,7 +74,7 @@ class RssIndividualQuestionFeed(Feed): ) return itertools.chain(*chain_elements) - + def item_title(self, item): """returns the title for the item """ @@ -77,7 +86,7 @@ class RssIndividualQuestionFeed(Feed): elif item.post_type == "comment": title = "Comment by %s for %s" % (item.author, self.title) return title - + def item_description(self, item): """returns the description for the item """ @@ -87,16 +96,24 @@ class RssIndividualQuestionFeed(Feed): class RssLastestQuestionsFeed(Feed): """rss feed class for the latest questions """ - title = askbot_settings.APP_TITLE + _(' - ')+ _('latest questions') - link = askbot_settings.APP_URL - description = askbot_settings.APP_DESCRIPTION - #ttl = 10 - copyright = askbot_settings.APP_COPYRIGHT + + def title(self): + return askbot_settings.APP_TITLE + _(' - ') + \ + _('Individual question feed') + + def feed_copyright(self): + return askbot_settings.APP_COPYRIGHT + + def description(self): + return askbot_settings.APP_DESCRIPTION def item_link(self, item): """get full url to the item """ - return self.link + item.get_absolute_url() + return askbot_settings.APP_URL + item.get_absolute_url() + + def link(self): + return askbot_settings.APP_URL def item_author_name(self, item): """get name of author @@ -117,10 +134,10 @@ class RssLastestQuestionsFeed(Feed): """returns url without the slug because the slug can change """ - return self.link + item.get_absolute_url(no_slug = True) - + return askbot_settings.APP_URL + item.get_absolute_url(no_slug = True) + def item_description(self, item): - """returns the desciption for the item + """returns the description for the item """ return item.text @@ -142,12 +159,12 @@ class RssLastestQuestionsFeed(Feed): if tags: #if there are tags in GET, filter the #questions additionally - for tag in tags: + for tag in tags: qs = qs.filter(thread__tags__name = tag) - + return qs.order_by('-thread__last_activity_at')[:30] - + def main(): """main function for use as a script diff --git a/askbot/middleware/locale.py b/askbot/middleware/locale.py new file mode 100644 index 00000000..c92e977a --- /dev/null +++ b/askbot/middleware/locale.py @@ -0,0 +1,26 @@ +"Taken from django.middleware.locale: this is the locale selecting middleware that will look at accept headers" + +from django.utils.cache import patch_vary_headers +from django.utils import translation +from askbot.conf import settings + +class LocaleMiddleware(object): + """ + This is a very simple middleware that parses a request + and decides what translation object to install in the current + thread context. This allows pages to be dynamically + translated to the language the user desires (if the language + is available, of course). + """ + + def process_request(self, request): + language = settings.ASKBOT_LANGUAGE + translation.activate(language) + request.LANGUAGE_CODE = translation.get_language() + + def process_response(self, request, response): + patch_vary_headers(response, ('Accept-Language',)) + if 'Content-Language' not in response: + response['Content-Language'] = translation.get_language() + translation.deactivate() + return response diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index b1d7dd06..0aabcbe0 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -98,6 +98,7 @@ TEMPLATE_LOADERS = ( MIDDLEWARE_CLASSES = ( #'django.middleware.gzip.GZipMiddleware', + 'askbot.middleware.locale.LocaleMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', #'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache index 855e6294..99023524 100644 --- a/askbot/setup_templates/settings.py.mustache +++ b/askbot/setup_templates/settings.py.mustache @@ -97,6 +97,7 @@ TEMPLATE_LOADERS = ( MIDDLEWARE_CLASSES = ( #'django.middleware.gzip.GZipMiddleware', + 'askbot.middleware.locale.LocaleMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', #'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', diff --git a/askbot/skins/default/templates/main_page/tab_bar.html b/askbot/skins/default/templates/main_page/tab_bar.html index 8b666155..17ab810e 100644 --- a/askbot/skins/default/templates/main_page/tab_bar.html +++ b/askbot/skins/default/templates/main_page/tab_bar.html @@ -3,9 +3,9 @@ {% cache 0 "scope_sort_tabs" search_tags request.user author_name scope sort query context.page language_code %} <a class="rss" {% if feed_url %} - href="{{settings.APP_URL}}{{feed_url}}" + href="{{feed_url}}" {% else %} - href="{{settings.APP_URL}}/feeds/rss/" + href="/feeds/rss/" {% endif %} title="{% trans %}subscribe to the questions feed{% endtrans %}" >{% trans %}RSS{% endtrans %} diff --git a/askbot/skins/utils.py b/askbot/skins/utils.py index a07b1fa9..dee14e56 100644 --- a/askbot/skins/utils.py +++ b/askbot/skins/utils.py @@ -3,7 +3,7 @@ the lookup resolution process for templates and media works as follows: * look up item in selected skin * if not found look in 'default' -* raise an exception +* raise an exception """ import os import logging @@ -56,7 +56,7 @@ def get_available_skins(selected=None): #re-insert default as a last item skins['default'] = default_dir - skins['common'] = common_dir + skins['common'] = common_dir return skins @@ -71,7 +71,7 @@ def get_path_to_skin(skin): return skin_dirs.get(skin, None) def get_skin_choices(): - """returns a tuple for use as a set of + """returns a tuple for use as a set of choices in the form""" skin_names = list(reversed(get_available_skins().keys())) return zip(skin_names, skin_names) @@ -86,7 +86,7 @@ def resolve_skin_for_media(media=None, preferred_skin = None): def get_media_url(url, ignore_missing = False): """returns url prefixed with the skin name - of the first skin that contains the file + of the first skin that contains the file directories are searched in this order: askbot_settings.ASKBOT_DEFAULT_SKIN, then 'default', then 'commmon' if file is not found - returns None @@ -156,7 +156,7 @@ def get_media_url(url, ignore_missing = False): url = django_settings.STATIC_URL + use_skin + '/media/' + url url = os.path.normpath(url).replace('\\', '/') - + if resource_revision: url += '?v=%d' % resource_revision @@ -174,7 +174,7 @@ def update_media_revision(skin = None): if skin in get_skin_choices(): skin_path = get_path_to_skin(skin) else: - raise MediaNotFound('Skin %s not found' % skin) + raise MediaNotFound('Skin %s not found' % skin) else: skin = 'default' skin_path = get_path_to_skin(askbot_settings.ASKBOT_DEFAULT_SKIN) @@ -193,6 +193,6 @@ def update_media_revision(skin = None): if current_hash != askbot_settings.MEDIA_RESOURCE_REVISION_HASH: askbot_settings.update('MEDIA_RESOURCE_REVISION', resource_revision + 1) - askbot_settings.update('MEDIA_RESOURCE_REVISION_HASH', current_hash) + askbot_settings.update('MEDIA_RESOURCE_REVISION_HASH', current_hash) logging.debug('MEDIA_RESOURCE_REVISION changed') askbot_settings.MEDIA_RESOURCE_REVISION |