1. Artur Barseghyan
  2. django-slim

Commits

Artur Barseghyan  committed 7a2f3d4 Draft

0.7; added simplified use of local language names

  • Participants
  • Parent commits d6b02ec
  • Branches default
  • Tags 0.7

Comments (0)

Files changed (15)

File docs/conf.py

View file
 # built documents.
 #
 # The short X.Y version.
-version = '0.6'
+version = '0.7'
 # The full version, including alpha/beta/rc tags.
-release = '0.6'
+release = '0.7'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.

File example/example/local_settings.py

View file
 DEFAULT_FROM_EMAIL = '<no-reply@example.com>'
 
 SLIM_USE_LOCALEURL = True
+SLIM_USE_LOCAL_LANGUAGE_NAMES = True

File setup.py

View file
 except:
   readme = ''
 
-version = '0.6'
+version = '0.7'
 
 install_requires = [
     'six==1.4.1',

File src/slim/admin.py

View file
 __title__ = 'slim.admin'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('SlimAdmin',)
 

File src/slim/conf.py

View file
 __title__ = 'slim.conf'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('get_setting',)
 

File src/slim/defaults.py

View file
 __title__ = 'slim.defaults'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
-__all__ = ('USE_LOCALEURL', 'ENABLE_MONKEY_PATCHING')
+__all__ = ('USE_LOCALEURL', 'USE_LOCAL_LANGUAGE_NAMES', 'ENABLE_MONKEY_PATCHING')
 
 # If set to False, `django-localeurl` usage in `slim` is force-disabled.
 USE_LOCALEURL = True
 
+# If set to True, local language names are used.
+USE_LOCAL_LANGUAGE_NAMES = False
+
 # If set to True, class methods (``snart.models.Snart`` are monkey patched to the field, thus you don't have to
 # inherit from snart models.
 ENABLE_MONKEY_PATCHING = False

File src/slim/exceptions.py

View file
 __title__ = 'slim.exceptions'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('LocaleurlImportError',)
 

File src/slim/helpers.py

View file
 __title__ = 'slim.helpers'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('get_default_language', 'default_language', 'get_languages', 'get_languages_keys', \
            'get_language_from_request', 'get_languages_dict', 'admin_change_url', 'admin_add_url', 'smart_resolve')
 
 from django.conf import settings
 from django.core.urlresolvers import reverse
+from django.utils.translation import get_language_info
 
+from slim.settings import USE_LOCAL_LANGUAGE_NAMES
 
 def get_default_language():
     """
 
     :return iterable:
     """
-    return settings.LANGUAGES
+    if not USE_LOCAL_LANGUAGE_NAMES:
+        return settings.LANGUAGES
+    else:
+        languages = []
+        for lang_code, lang_name in settings.LANGUAGES:
+            try:
+                lang_name = get_language_info(lang_code)['name_local']
+            except Exception as e:
+                pass
+            languages.append((lang_code, lang_name))
+        return languages
 
 
 def get_languages_keys():
 
     :return dict:
     """
-    return dict(settings.LANGUAGES)
+    return dict(get_languages())
 
 
 def get_language_from_request(request, default=default_language):

File src/slim/models/__init__.py

View file
 __title__ = 'slim.models.__init__'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('Slim', 'SlimBaseModel')
 

File src/slim/models/decorators.py

View file
 __title__ = 'slim.models.decorators'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('prepend_language', 'localeurl_prepend_language', 'auto_prepend_language')
 

File src/slim/models/fields.py

View file
 __title__ = 'slim.models.fields'
-__version__ = '0.5'
-__build__ = 0x000005
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('LanguageField', 'SimpleLanguageField')
 

File src/slim/settings.py

View file
 __title__ = 'slim.settings'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
-__all__ = ('USE_LOCALEURL', 'ENABLE_MONKEY_PATCHING')
+__all__ = ('USE_LOCALEURL', 'USE_LOCAL_LANGUAGE_NAMES', 'ENABLE_MONKEY_PATCHING')
 
 from slim.conf import get_setting
 
 USE_LOCALEURL = get_setting('USE_LOCALEURL')
+USE_LOCAL_LANGUAGE_NAMES = get_setting('USE_LOCAL_LANGUAGE_NAMES')
 ENABLE_MONKEY_PATCHING = get_setting('ENABLE_MONKEY_PATCHING')

File src/slim/templatetags/slim_tags.py

View file
 __title__ = 'slim.templatetags.slim_tags'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('get_translated_object_for', 'get_translated_objects_for', 'set_language', 'multiling_is_enabled',
            'slim_language_name')
     :return str:
     """
     return _(get_languages_dict()[lang_code])
+
+
+@register.filter
+def slim_language_local_name(lang_code):
+    """
+    Localised language name.
+
+    :param str lang_code:
+    :return str:
+    """
+    try:
+        return translation.get_language_info(lang_code)['name_local']
+    except:
+        return lang_code
+

File src/slim/translations.py

View file
 __title__ = 'slim.translations'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('short_language_code', 'is_primary_language')
 

File src/slim/utils.py

View file
 __title__ = 'slim.utils'
-__version__ = '0.6'
-__build__ = 0x000006
+__version__ = '0.7'
+__build__ = 0x000007
 __author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
 __all__ = ('locale_url_is_installed',)