Permalink
Browse files

new i18n settings and testsuite working

  • Loading branch information...
1 parent b6fde0a commit 1edf5647ddb38fac89e329e73c8c651765ecd2b2 @digi604 digi604 committed Oct 1, 2012
View
@@ -3,6 +3,7 @@
from cms.forms.widgets import UserSelectAdminWidget
from cms.models import (Page, PagePermission, PageUser, ACCESS_PAGE,
PageUserGroup)
+from cms.utils.i18n import get_language_tuple, get_language_list
from cms.utils.mail import mail_page_user_change
from cms.utils.page import is_valid_page_slug
from cms.utils.page_resolver import get_page_from_path, is_valid_url
@@ -60,7 +61,7 @@ class PageAddForm(forms.ModelForm):
help_text=_('The default title'))
slug = forms.CharField(label=_("Slug"), widget=forms.TextInput(),
help_text=_('The part of the title that is used in the URL'))
- language = forms.ChoiceField(label=_("Language"), choices=settings.CMS_LANGUAGES,
+ language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
help_text=_('The current language of the content fields.'))
class Meta:
@@ -74,13 +75,7 @@ def __init__(self, *args, **kwargs):
if not self.fields['site'].initial:
self.fields['site'].initial = Site.objects.get_current().pk
site_id = self.fields['site'].initial
- languages = []
- language_mappings = dict(settings.LANGUAGES)
- if site_id in settings.CMS_SITE_LANGUAGES:
- for lang in settings.CMS_SITE_LANGUAGES[site_id]:
- languages.append((lang, language_mappings.get(lang, lang)))
- else:
- languages = settings.CMS_LANGUAGES
+ languages = get_language_tuple(site_id)
self.fields['language'].choices = languages
if not self.fields['language'].initial:
self.fields['language'].initial = get_language()
@@ -142,7 +137,7 @@ def clean_slug(self):
def clean_language(self):
language = self.cleaned_data['language']
- if not language in dict(settings.CMS_LANGUAGES).keys():
+ if not language in get_language_list():
raise ValidationError("Given language does not match language settings.")
return language
View
@@ -17,6 +17,7 @@
from cms.utils import (copy_plugins, helpers, moderator, permissions, plugins,
get_template_from_request, get_language_from_request,
placeholder as placeholder_utils, admin as admin_utils, cms_static_url)
+from cms.utils.i18n import get_language_dict, get_language_list, get_language_tuple, get_language_object
from cms.utils.page_resolver import is_valid_url
from cms.utils.admin import jsonify_request
from cms.utils.permissions import has_plugin_permission
@@ -441,13 +442,13 @@ def get_form(self, request, obj=None, **kwargs):
installed_plugins = plugin_pool.get_all_plugins(placeholder_name, obj)
plugin_list = CMSPlugin.objects.filter(language=language, placeholder=placeholder, parent=None).order_by('position')
other_plugins = CMSPlugin.objects.filter(placeholder=placeholder, parent=None).exclude(language=language)
- dict_cms_languages = dict(settings.CMS_LANGUAGES)
+ dict_cms_languages = get_language_dict()
for plugin in other_plugins:
if (not plugin.language in copy_languages) and (plugin.language in dict_cms_languages):
copy_languages[plugin.language] = dict_cms_languages[plugin.language]
language = get_language_from_request(request, obj)
- if copy_languages and len(settings.CMS_LANGUAGES) > 1:
+ if copy_languages and len(get_language_list()) > 1:
show_copy = True
widget = PluginEditor(attrs={
'installed': installed_plugins,
@@ -565,14 +566,7 @@ def _get_site_languages(self, obj):
site_id = None
if obj:
site_id = obj.site_id
- languages = []
- if site_id and site_id in settings.CMS_SITE_LANGUAGES:
- for lang in settings.CMS_SITE_LANGUAGES[site_id]:
- lang_label = dict(settings.CMS_LANGUAGES).get(lang, dict(settings.LANGUAGES).get(lang, lang))
- languages.append((lang, lang_label))
- else:
- languages = settings.CMS_LANGUAGES
- return languages
+ return get_language_tuple(site_id)
def update_language_tab_context(self, request, obj, context=None):
if not context:
@@ -675,11 +669,7 @@ def changelist_view(self, request, extra_context=None):
site_id = int(site_id)
# languages
- languages = []
- if site_id and site_id in settings.CMS_SITE_LANGUAGES:
- languages = settings.CMS_SITE_LANGUAGES[site_id]
- else:
- languages = [lang[0] for lang in settings.CMS_LANGUAGES]
+ languages = get_language_list(site_id)
# parse the cookie that saves which page trees have
# been opened already and extracts the page ID
@@ -985,7 +975,7 @@ def delete_translation(self, request, object_id, extra_context=None):
raise PermissionDenied
message = _('Title and plugins with language %(language)s was deleted') % {
- 'language': [name for code, name in settings.CMS_LANGUAGES if code == language][0]
+ 'language': get_language_object(language)['name']
}
self.log_change(request, titleobj, message)
self.message_user(request, message)
@@ -1188,7 +1178,7 @@ def copy_plugins(self, request):
if not page.has_change_permission(request):
return HttpResponseForbidden(ugettext("You do not have permission to change this page"))
- if not language or not language in [ lang[0] for lang in settings.CMS_LANGUAGES ]:
+ if not language or not language in get_language_list():
return HttpResponseBadRequest(ugettext("Language must be set to a supported language!"))
if language == copy_from:
return HttpResponseBadRequest(ugettext("Language must be different than the copied language!"))
View
@@ -7,6 +7,7 @@
calling these methods!
"""
import datetime
+from cms.utils.i18n import get_language_list
from django.conf import settings
from django.contrib.auth.models import User
@@ -125,7 +126,7 @@ def create_page(title, template, language, menu_title=None, slug=None,
assert template in [tpl[0] for tpl in settings.CMS_TEMPLATES]
# validate language:
- assert language in [lang[0] for lang in settings.CMS_LANGUAGES]
+ assert language in get_language_list()
# set default slug:
if not slug:
@@ -220,7 +221,7 @@ def create_title(language, title, page, menu_title=None, slug=None,
See docs/extending_cms/api_reference.rst for more info
"""
# validate language:
- assert language in [lang[0] for lang in settings.CMS_LANGUAGES]
+ assert language in get_language_list()
# validate page
assert isinstance(page, Page)
View
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
from cms.apphook_pool import apphook_pool
-from cms.utils.i18n import force_language
+from cms.utils.i18n import force_language, get_language_list
from cms.utils.moderator import get_page_queryset
from django.conf import settings
@@ -31,7 +31,7 @@ def applications_page_check(request, current_page=None, path=None):
# This removes the non-CMS part of the URL.
path = request.path.replace(reverse('pages-root'), '', 1)
# check if application resolver can resolve this
- for lang, lang_name in settings.CMS_LANGUAGES:
+ for lang in get_language_list():
if path.startswith(lang+"/"):
path = path[len(lang+"/"):]
for resolver in APP_RESOLVERS:
@@ -70,34 +70,45 @@
# Wheter the cms has a softroot functionionality
CMS_SOFTROOT = False
-#Hide untranslated Pages
-CMS_HIDE_UNTRANSLATED = True
-#Fall back to another language if the requested page isn't available in the preferred language
-CMS_LANGUAGE_FALLBACK = True
-#Configuration on how to order the fallbacks for languages.
-# example: {'de': ['en', 'fr'],
-# 'en': ['de'],
-# }
-CMS_LANGUAGE_CONF = {}
+# Defines which languages should be offered and what are the defaults
+# example:
+# CMS_LANGUAGES = {
+# 1: [
+# {
+# 'code': 'en',
+# 'name': _('English'),
+# 'fallbacks': ['de', 'fr'],
+# 'public': True,
+# 'hide_untranslated': True,
+# 'redirect_on_fallback':False,
+# },
+# {
+# 'code': 'de',
+# 'name': _('Deutsch'),
+# 'fallbacks': ['en', 'fr'],
+# 'public': True,
+# },
+# {
+# 'code': 'fr',
+# 'public': False,
+# }
+# ],
+# 'defaults': {
+# 'fallbacks': ['en', 'de', 'fr'],
+# 'redirect_on_fallback':True,
+# 'public': False,
+# 'hide_untranslated': False,
+# }
+#}
+
+CMS_LANGUAGES = {}
-# Defines which languages should be offered.
-CMS_LANGUAGES = settings.LANGUAGES
-
-# If you have different sites with different languages you can configure them here
-# and you will only be able to edit the languages that are actually on the site.
-# example: {1:['en','de'],
-# 2:['en','fr'],
-# 3:['en'],}
-CMS_SITE_LANGUAGES = {}
CMS_SITE_CHOICES_CACHE_KEY = 'CMS:site_choices'
CMS_PAGE_CHOICES_CACHE_KEY = 'CMS:page_choices'
-# Languages that are visible in the frontend (Language Chooser)
-CMS_FRONTEND_LANGUAGES = [x[0] for x in CMS_LANGUAGES]
-
# Path for CMS media (uses <MEDIA_ROOT>/cms by default)
CMS_MEDIA_PATH = 'cms/'
View
@@ -46,3 +46,32 @@ def post_patch_check():
"I can't find the namespaces in %r."
% template[0]
)
+ VALID_LANG_PROPS = ['code', 'name', 'fallbacks', 'hide_untranslated', 'redirect_on_fallback', 'public']
+
+ for site in settings.CMS_LANGUAGES.keys():
+ try:
+ int(site)
+ except ValueError:
+ if not site =="default":
+ raise ImproperlyConfigured("CMS_LANGUAGES can only be filled with integers (site ids) and 'default' for\n"
+ " default values. %s is not a valid key." % site)
+ for lang in settings.CMS_LANGUAGES[site]:
+ if site == "default":
+ if lang not in VALID_LANG_PROPS:
+ raise ImproperlyConfigured("CMS_LANGUAGES has an invalid property on the site %(site)s and language %(language)s: %(property)s" % {'site':site, 'language':lang['code'], 'property':key})
+ continue
+ if not "code" in lang.keys():
+ raise ImproperlyConfigured("CMS_LANGUAGES has language without a 'code' property")
+ if not 'name' in lang.keys():
+ raise ImproperlyConfigured("CMS_LANGUAGES has a language without a 'name' property")
+ for key in lang.keys():
+ if key not in VALID_LANG_PROPS:
+ raise ImproperlyConfigured("CMS_LANGUAGES has an invalid property on the site %(site)s and language %(language)s: %(property)s" % {'site':site, 'language':lang['code'], 'property':key})
+
+
+
+
+
+
+
+
View
@@ -6,7 +6,7 @@
from cms.models.permissionmodels import PagePermission, GlobalPagePermission
from cms.models.titlemodels import Title
from cms.utils import get_language_from_request
-from cms.utils.i18n import get_fallback_languages
+from cms.utils.i18n import get_fallback_languages, hide_untranslated
from cms.utils.moderator import get_page_queryset, get_title_queryset
from cms.utils.plugins import current_site
from menus.base import Menu, NavigationNode, Modifier
@@ -229,7 +229,7 @@ def get_nodes(self, request):
'site':site,
}
- if settings.CMS_HIDE_UNTRANSLATED:
+ if hide_untranslated(lang, site.pk):
filters['title_set__language'] = lang
pages = page_queryset.published().filter(**filters).order_by("tree_id", "lft")
View
@@ -530,6 +530,8 @@ def get_languages(self):
self.all_languages = Title.objects.filter(page=self).values_list("language", flat=True).distinct()
self.all_languages = list(self.all_languages)
self.all_languages.sort()
+ for x in xrange(len(self.all_languages)):
+ self.all_languages[x] = str(self.all_languages[x])
return self.all_languages
def get_cached_ancestors(self, ascending=True):
@@ -1,11 +1,11 @@
+from cms.utils.i18n import get_language_tuple
from django.db import models
from django.utils.translation import ugettext_lazy as _
from cms.models import CMSPlugin, Page
-from django.conf import settings
class InheritPagePlaceholder(CMSPlugin):
"""
Provides the ability to inherit plugins for a certain placeholder from an associated "parent" page instance
"""
from_page = models.ForeignKey(Page, null=True, blank=True, help_text=_("Choose a page to include its plugins into this placeholder, empty will choose current page"))
- from_language = models.CharField(_("language"), max_length=5, choices=settings.CMS_LANGUAGES, blank=True, null=True, help_text=_("Optional: the language of the plugins you want"))
+ from_language = models.CharField(_("language"), max_length=5, choices=get_language_tuple(), blank=True, null=True, help_text=_("Optional: the language of the plugins you want"))
@@ -4,6 +4,7 @@
from classytags.helpers import InclusionTag
from cms.models import MASK_PAGE, MASK_CHILDREN, MASK_DESCENDANTS
from cms.utils.admin import get_admin_menu_item_context
+from cms.utils.i18n import get_language_object
from cms.utils.permissions import get_any_page_view_permissions
from distutils.version import LooseVersion
from django import template
@@ -209,7 +210,7 @@ def get_context(self, context):
'is_popup': is_popup,
'show_save': True,
'language': language,
- 'language_name': [name for langcode, name in settings.CMS_LANGUAGES if langcode == language][0],
+ 'language_name': get_language_object(language)['name'],
'show_delete_translation': show_delete_translation
}
register.tag(PageSubmitRow)
View
@@ -104,21 +104,55 @@ def configure(**extra):
('pt-br', gettext('Brazilian Portuguese')),
('nl', gettext("Dutch")),
),
- CMS_LANGUAGES = (
- ('en', gettext('English')),
- ('fr', gettext('French')),
- ('de', gettext('German')),
- ('pt-br', gettext('Brazilian Portuguese')),
- ('nl', gettext("Dutch")),
- ),
- CMS_LANGUAGE_CONF = {
- 'de':['fr', 'en'],
- 'en':['fr', 'de'],
- },
- CMS_SITE_LANGUAGES = {
- 1:['en','de','fr','pt-br'],
- 2:['de','fr'],
- 3:['nl'],
+ CMS_LANGUAGES = {
+ 1: [
+ {
+ 'code':'en',
+ 'name':gettext('English'),
+ 'fallbacks':['fr','de'],
+ 'public':True,
+ },
+ {
+ 'code':'de',
+ 'name':gettext('German'),
+ 'fallbacks':['fr','en'],
+ 'public':True,
+ },
+ {
+ 'code':'fr',
+ 'name':gettext('French'),
+ 'public':True,
+ },
+ {
+ 'code':'pt-br',
+ 'name':gettext('Brazilian Portuguese'),
+ 'public':True,
+ },
+ ],
+ 2: [
+ {
+ 'code':'de',
+ 'name':gettext('German'),
+ 'fallbacks':['fr','en'],
+ 'public':True,
+ },
+ {
+ 'code':'fr',
+ 'name':gettext('French'),
+ 'public':True,
+ },
+ ],
+ 3: [
+ {
+ 'code':'nl',
+ 'name':gettext('Dutch'),
+ 'fallbacks':['fr','en'],
+ 'public':True,
+ },
+ ],
+ 'default': {
+ 'hide_untranslated':False,
+ },
},
CMS_TEMPLATES = (
('col_two.html', gettext('two columns')),
@@ -163,7 +197,6 @@ def configure(**extra):
CMS_SEO_FIELDS = True,
CMS_FLAT_URLS = False,
CMS_MENU_TITLE_OVERWRITE = True,
- CMS_HIDE_UNTRANSLATED = False,
CMS_URL_OVERWRITE = True,
CMS_SHOW_END_DATE = True,
CMS_SHOW_START_DATE = True,
Oops, something went wrong.

0 comments on commit 1edf564

Please sign in to comment.