def get_django_lang_name(code, all_codes):
    code = code.lower().replace('_', '-')
    code_orig = code
    lang_info = LANG_INFO.get(code)
    if not lang_info:
        code = code.split('-', 1)[0]
        if code not in all_codes:
            lang_info = LANG_INFO.get(code)
    if lang_info:
        return code, lang_info['name']
    else:
        return code_orig, code_orig
예제 #2
0
def get_language_info(lang_code):
    from django.conf.locale import LANG_INFO
    # Add custom languages
    LANG_INFO.update(
        {
            'tlh': {
                'bidi': False,
                'code': 'tlh',
                'name': 'Klingon',
                'name_local': u'tlhIngan Hol',# \uf8e4\uf8d7\uf8dc\uf8db \uf8d6\uf8dd\uf8d9',
            },
            'cs-cz': {
                'bidi': False,
                'code': 'cs',
                'name': 'Czech',
                'name_local': u'\u010desky (\u010cesk\xe1 republika)',
            },
        }
    )

    try:
        return LANG_INFO[lang_code]
    except KeyError:
        raise KeyError("Unknown language code %r." % lang_code)
예제 #3
0
def get_names():
    from six.moves.urllib.request import Request
    import json
    request = Request(MOMENT_COMPONENT_JSON_URL)
    moment_component_files = json.loads(retry_urlopen(request).decode())["files"]
    moment_supported_langs_set = set([name.replace("locale/", "").replace(".js", "")
                              for name in moment_component_files
                              if name.startswith("locale/")])

    from django.conf.locale import LANG_INFO
    django_supported_langs = set(list(LANG_INFO.keys()))

    moment_already_supported = (
        moment_supported_langs_set.intersection(django_supported_langs))

    known_fallbacks = {
        # For Chinese
        'zh-hans': "zh-cn",
        'zh-my': "zh-cn",
        'zh-sg': "zh-cn",
        'zh-hant': "zh-tw",  # or 'zh-hk'
        'zh-mo': "zh-tw",

        # For Spanish
        'es-ar': "es",
        'es-co': "es",
        'es-mx': "es",
        'es-ni': "es",
        'es-ve': "es",
    }

    for l in known_fallbacks.keys():
        try:
            assert l not in moment_already_supported
        except:
            raise ValueError("'%s' is now supported by moment.js, "
                             "please remove it from known_fallbacks" % l)

    not_supported = (
        django_supported_langs
            .difference(moment_supported_langs_set)
            .difference(set(list(known_fallbacks.keys())))
            .difference({"en", "en-us"}))

    print(repr(known_fallbacks))
    print(repr(sorted(list(not_supported))))
예제 #4
0
class Setting(models.Model):
    user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)

    timezone = TimeZoneField(default='UTC')

    LOCALES = [(li['code'], li['name_local']) for li in LANG_INFO.values()
               if not li.get('fallback')]
    locale = models.CharField(max_length=10, choices=LOCALES, default='en')

    DURATION_FORMAT_CLASSIC = 1
    DURATION_FORMAT_DECIMAL = 2
    DURATION_FORMATS = [
        (DURATION_FORMAT_CLASSIC, 'Classic (3:45)'),
        (DURATION_FORMAT_DECIMAL, 'Decimal (3.75)'),
    ]
    duration_format = models.PositiveSmallIntegerField(
        choices=DURATION_FORMATS, default=DURATION_FORMAT_CLASSIC)

    allow_parallel_tracking = BooleanField(default=False)
예제 #5
0
    def test_all_locales(self):
        formatter = ExcelDateFormatter()

        for lang in LANG_INFO.keys():
            with self.subTest(lang), translation.override(lang):
                self.assertNotEqual(formatter.get(), "")
예제 #6
0
METHOD_CHOICES = (
    ('google', 'Google App Engine'),
    ('gunicorn', 'Gunicorn'),
    ('mod_python', 'mod_python'),
    ('mod_wsgi', 'mod_wsgi'),
    ('fastcgi', 'FastCGI'),
    ('dev', 'Django Development Server'),
    ('scgi', 'Simple CGI (scgi)'),
    ('tornado', 'Tornado'),
    ('wsgi', 'wsgi'),
    ('uwsgi', 'uWSGI'),
    ('paas', 'PAAS (Heroku, GAE, Gondor, etc'),
)

LANGUAGE_CHOICES = []
for language in LANG_INFO.keys():
    LANGUAGE_CHOICES.append((LANG_INFO[language]['code'], LANG_INFO[language]['name']))


class Website(models.Model):
    title = models.CharField(max_length=100)
    url = models.URLField(unique=True)
    slug = models.SlugField(editable=False, blank=True, null=True, max_length=250)
    owner = models.ForeignKey(User, blank=True, null=True, editable=False)
    description = models.TextField()
    tags = TagField(blank=True, null=True)
    verified = models.BooleanField(blank=True, default=False, editable=False)
    created = models.DateTimeField(blank=True, null=True, editable=False)
    
    comment_count = models.IntegerField(blank=True, null=True, editable=False)
    num_votes = models.IntegerField(blank=True, null=True, editable=False)
예제 #7
0
# =============================================================================
# Generic Django project settings
# =============================================================================

DEBUG = True

SITE_ID = 1
# Add languages we're missing from Django
LANG_INFO.update({
    'am-et': {
        'bidi': False,
        'name': 'Amharic',
        'code': 'am-et',
        'name_local': 'አማርኛ'
    },
    'zh': {
        'bidi': False,
        'code': 'zh',
        'name': 'Chinese',
        'name_local': '简体中文',
    },
})
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
TIME_ZONE = 'UTC'
USE_TZ = True
USE_I18N = False
USE_L10N = True
LANGUAGE_CODE = 'en'
LANGUAGES = (
    ('am-et', 'Amharic'),
예제 #8
0
 def _set_available_langs(self, context):
     available_langs = self._search_for_attr_from_context('lang', context)
     context['available_langs'] = [
         (lang, LANG_INFO.get(lang, {}).get('name_local', lang))
         for lang in available_langs
     ]
예제 #9
0
LANG_INFO.update({
    'am': {
        'bidi': False,
        'name': 'Amharic',
        'code': 'am',
        'name_local': u'አማርኛ'
    },
    'bm': {
        'bidi': False,
        'name': 'Bambara',
        'code': 'bm',
        'name_local': 'Bambara'
    },
    'ckb': {
        'bidi': True,
        'name': 'Soranî',
        'code': 'ckb',
        'name_local': 'سۆرانی',
    },
    'ku': {
        'bidi': False,
        'name': 'Kurdish',
        'code': 'ku',
        'name_local': 'Kurdî'
    },
    'ln': {
        'bidi': False,
        'name': 'Lingala',
        'code': 'ln',
        'name_local': 'Lingála'
    },
    'ps': {
        'bidi': True,
        'name': 'Pashto',
        'code': 'ps',
        'name_local': 'پښتو'
    },
    'rn': {
        'bidi': False,
        'name': 'Kirundi',
        'code': 'rn',
        'name_local': 'kirundi'
    },
    'so': {
        'bidi': False,
        'name': 'Somali',
        'code': 'so',
        'name_local': u'Af-Soomaali'
    },
    'ti': {
        'bidi': False,
        'name': 'Tigrinya',
        'code': 'bm',
        'name_local': 'ትግርኛ'
    },
    'wo': {
        'bidi': False,
        'name': 'Wolof',
        'code': 'wo',
        'name_local': 'wolof'
    },
})
예제 #10
0
파일: models.py 프로젝트: aborsu/multichat
from django.db import models
from django.conf.locale import LANG_INFO
from django.db import transaction

LANGUAGE_CHOICE = tuple([(k, v['name']) for k, v in LANG_INFO.items()
                         if v.get('name')])


class Dataset(models.Model):
    name = models.CharField(max_length=255, unique=True)
    language = models.CharField(max_length=7, choices=LANGUAGE_CHOICE)

    @staticmethod
    @transaction.atomic
    def load_rasa_dataset(rasa_nlu_data, name, language):
        dataset = Dataset.objects.create(name=name, language=language)
        entity_types = {}
        for raw_example in rasa_nlu_data['common_examples']:
            text = raw_example['text']
            intent = raw_example['intent']

            example = Example.objects.create(dataset=dataset,
                                             text=text,
                                             intent=intent)
            for raw_entity in raw_example['entities']:
                start = raw_entity['start']
                end = raw_entity['end']
                value = raw_entity['value']
                raw_type = raw_entity['entity']

                if raw_type not in entity_types:
예제 #11
0
METHOD_CHOICES = (
    ('google', 'Google App Engine'),
    ('gunicorn', 'Gunicorn'),
    ('mod_python', 'mod_python'),
    ('mod_wsgi', 'mod_wsgi'),
    ('fastcgi', 'FastCGI'),
    ('dev', 'Django Development Server'),
    ('scgi', 'Simple CGI (scgi)'),
    ('tornado', 'Tornado'),
    ('wsgi', 'wsgi'),
    ('uwsgi', 'uWSGI'),
    ('paas', 'PAAS (Heroku, GAE, Gondor, etc'),
)

LANGUAGE_CHOICES = []
for language in LANG_INFO.keys():
    LANGUAGE_CHOICES.append(
        (LANG_INFO[language]['code'], LANG_INFO[language]['name']))


class Website(models.Model):
    title = models.CharField(max_length=100)
    url = models.URLField(unique=True)
    slug = models.SlugField(editable=False,
                            blank=True,
                            null=True,
                            max_length=250)
    owner = models.ForeignKey(User, blank=True, null=True, editable=False)
    description = models.TextField()
    tags = TagField(blank=True, null=True)
    verified = models.BooleanField(blank=True, default=False, editable=False)
예제 #12
0
    SETTINGS_MODULE = sub.__name__
    sys.stdout.write('Importing settings from %s\n' % SETTINGS_MODULE)
    ldict = locals()
    for k in sub.__dict__:
        if k.isupper() and not k.startswith('__') or not k.endswith('__'):
            ldict[k] = sub.__dict__[k]
    USER_DATA_FIELDS = []
    for section, fields in USER_FORM_FIELDS:  # noqa
        USER_DATA_FIELDS.extend(fields)

    # Allow server settings to only define STORAGE_ROOT without needing to
    # redefine all ROOTS like settings.
    BACKUPED_ROOT = ldict.get('BACKUPED_ROOT') or os.path.join(STORAGE_ROOT, 'main')  # noqa
    MEDIA_ROOT = ldict.get('MEDIA_ROOT') or os.path.join(BACKUPED_ROOT, 'media')  # noqa
    STATIC_ROOT = ldict.get('STATIC_ROOT') or os.path.join(STORAGE_ROOT, 'static')  # noqa
    if not getattr(ldict, 'DATABASES', None):
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(BACKUPED_ROOT, 'default.sqlite'),
            },
        }
    LANGUAGES = []
    # Allow to override AVAILABLE_LANGUAGES in box settings, without needing
    # to override also LANGUAGES.
    for code, label in ldict.get('AVAILABLE_LANGUAGES'):
        LANGUAGES.append((code, label))
    # Some languages are missing from Django.
    from django.conf.locale import LANG_INFO
    LANG_INFO.update(EXTRA_LANG_INFO)  # noqa
예제 #13
0
    for k in sub.__dict__:
        if k.isupper() and not k.startswith('__') or not k.endswith('__'):
            ldict[k] = sub.__dict__[k]
    USER_DATA_FIELDS = []
    for section, fields in USER_FORM_FIELDS:  # noqa
        USER_DATA_FIELDS.extend(fields)

    # Allow server settings to only define STORAGE_ROOT without needing to
    # redefine all ROOTS like settings.
    BACKUPED_ROOT = ldict.get('BACKUPED_ROOT') or os.path.join(
        STORAGE_ROOT, 'main')  # noqa
    MEDIA_ROOT = ldict.get('MEDIA_ROOT') or os.path.join(
        BACKUPED_ROOT, 'media')  # noqa
    STATIC_ROOT = ldict.get('STATIC_ROOT') or os.path.join(
        STORAGE_ROOT, 'static')  # noqa
    if not getattr(ldict, 'DATABASES', None):
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(BACKUPED_ROOT, 'default.sqlite'),
            },
        }
    LANGUAGES = []
    # Allow to override AVAILABLE_LANGUAGES in box settings, without needing
    # to override also LANGUAGES.
    for code, label in ldict.get('AVAILABLE_LANGUAGES'):
        LANGUAGES.append((code, label))
    # Some languages are missing from Django.
    from django.conf.locale import LANG_INFO
    LANG_INFO.update(EXTRA_LANG_INFO)  # noqa
예제 #14
0
 def _set_available_langs(self, context):
     available_langs = self._search_for_attr_from_context('lang', context)
     context['available_langs'] = [
         (lang, LANG_INFO.get(lang, {}).get('name_local', lang))
         for lang in available_langs]
예제 #15
0
파일: base.py 프로젝트: ideascube/ideascube
LANG_INFO.update({
    '411': {
        'code': '411',
        'name_local': _('Suitable for all languages'),
    },
    'am': {
        'bidi': False,
        'name': 'Amharic',
        'code': 'am',
        'name_local': u'አማርኛ'
    },
    'bm': {
        'bidi': False,
        'name': 'Bambara',
        'code': 'bm',
        'name_local': 'Bambara'
    },
    'ckb': {
        'bidi': True,
        'name': 'Soranî',
        'code': 'ckb',
        'name_local': 'سۆرانی',
    },
    'fa-ir': {
        'bidi': True,
        'name': 'Persian',
        'code': 'fa-ir',
        'name_local': 'فارسی',
    },
    'kg': {
        'bidi': False,
        'name': 'Kongo',
        'code': 'kg',
        'name_local': 'Kikongo',
    },
    'ku': {
        'bidi': False,
        'name': 'Kurdish',
        'code': 'ku',
        'name_local': 'Kurdî'
    },
    'ln': {
        'bidi': False,
        'name': 'Lingala',
        'code': 'ln',
        'name_local': 'Lingála'
    },
    'lua': {
        'bidi': False,
        'name': 'Luba-Lulua',
        'code': 'lua',
        'name_local': 'Tshiluba',
    },
    'ps': {
        'bidi': True,
        'name': 'Pashto',
        'code': 'ps',
        'name_local': 'پښتو'
    },
    'rn': {
        'bidi': False,
        'name': 'Kirundi',
        'code': 'rn',
        'name_local': 'kirundi'
    },
    'so': {
        'bidi': False,
        'name': 'Somali',
        'code': 'so',
        'name_local': u'Af-Soomaali'
    },
    'ti': {
        'bidi': False,
        'name': 'Tigrinya',
        'code': 'bm',
        'name_local': 'ትግርኛ'
    },
    'wo': {
        'bidi': False,
        'name': 'Wolof',
        'code': 'wo',
        'name_local': 'wolof'
    },
    'my-mm': {
        'bidi': True,
        'name': 'Burmese',
        'code': 'my-mm',
        'name_local': 'မြန်မာဘာသာ ',
    },
})
예제 #16
0
from django.db import models
from django.conf.locale import LANG_INFO
from .validators import validate_numeric, validate_date

LANG_CHOICES = [(key, value.get('name')) for key, value in LANG_INFO.items()
                if value.get('name')]


class Author(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.name


class Identifier(models.Model):
    CHOICES = (('ISBN_13', 'ISBN 13'), ('ISBN_10', 'ISBN 10'))
    type = models.CharField(max_length=7, choices=CHOICES)
    identifier = models.CharField(max_length=60, validators=[validate_numeric])

    class Meta:
        unique_together = ['type', 'identifier']

    def __str__(self):
        return '{}: {}'.format(self.type, self.identifier)


class ImageLinks(models.Model):
    smallThumbnail = models.URLField(blank=True, default='')
    thumbnail = models.URLField(blank=True, default='')