Example #1
0
 def validate(self, code):
     try:
         i18n.get_locale().territories[code]
     except KeyError:
         raise ValueError(
             'Could not convert string to country code: {0}'.format(code)
         )
Example #2
0
 def get_name(self, width='wide', context='format'):
     names = i18n.get_day_names(
         width,
         context,
         i18n.get_locale()
     )
     return names[self.index]
def get_all_countries():
    territories = [
        (code, name)
        for code, name in i18n.get_locale().territories.items()
        if len(code) == 2 and code not in ('QO', 'QU', 'ZZ')
    ]
    return sorted(territories, key=operator.itemgetter(1))
Example #4
0
def get_current_locale(obj):
    from sqlalchemy_utils import i18n

    locale = i18n.get_locale()
    if locale:
        return str(locale)
    return obj.locale
Example #5
0
 def _get_choices(self):
     # Get all territories and filter out continents (3-digit code)
     # and some odd territories such as "Unknown or Invalid Region"
     # ("ZZ"), "European Union" ("QU") and "Outlying Oceania" ("QO").
     territories = [
         (code, name)
         for code, name in i18n.get_locale().territories.iteritems()
         if len(code) == 2 and code not in ('QO', 'QU', 'ZZ')
     ]
     return sorted(territories, key=operator.itemgetter(1))
Example #6
0
 def position(self):
     return (
         self.index -
         i18n.get_locale().first_week_day
     ) % self.NUM_WEEK_DAYS
Example #7
0
 def name(self):
     return i18n.get_locale().territories[self.code]
Example #8
0
 def name(self):
     return i18n.get_locale().currencies[self.code]
Example #9
0
 def symbol(self):
     return i18n.babel.numbers.get_currency_symbol(
         self.code,
         i18n.get_locale()
     )
Example #10
0
 def get_name(self, width='wide', context='format'):
     names = i18n.get_day_names(width, context, i18n.get_locale())
     return names[self.index]
Example #11
0
 def validate(self, code):
     try:
         i18n.get_locale().territories[code]
     except KeyError:
         raise ValueError(
             'Could not convert string to country code: {0}'.format(code))
Example #12
0
 def name(self):
     return i18n.get_locale().territories[self.code]
Example #13
0
def compile_current_locale(element, compiler, **kw):
    # Lazy import get_locale so that it can be overridden
    from sqlalchemy_utils.i18n import get_locale

    return '%s' % compiler.process(
        sa.bindparam('current_locale', str(get_locale())))
Example #14
0
 def position(self):
     return (
         self.index -
         i18n.get_locale().first_week_day
     ) % self.NUM_WEEK_DAYS
Example #15
0
 def validate(self, code):
     try:
         i18n.get_locale().currencies[code]
     except KeyError:
         raise ValueError("{0}' is not valid currency code.")