Пример #1
0
    def test_renders_prices_with_correct_currency(self):
        assert_equals(u'1.024,00 €', self.generator.format_price(1024))

        self.generator.invoice.currency = 'USD'
        self.generator.format = Format(locale='en')
        assert_equals('en', str(self.generator.format.locale))
        assert_equals(u'$1,024.00', self.generator.format_price(1024))
Пример #2
0
 def __new__(cls, component, name, env=None):
     self = str.__new__(cls, name)
     self.component = component
     self.translations = component.translations[name]
     self.format = Format(name)
     self.locale = Locale(name)
     self._env = env
     return self
Пример #3
0
def _get_format():
    lang = translation.get_language()
    try:
        locale = Locale(translation.to_locale(lang))
    except UnknownLocaleError:
        locale = Locale(
            translation.to_locale(settings.BABEL_FALLBACK.get(lang, 'en-US')))
    return Format(locale)
Пример #4
0
 def __new__(cls, name, root, translations_dir, categories=[]):
     self = str.__new__(cls, name)
     self.format = Format(name)
     self.timezone = timezone('Europe/Moscow')
     self.root = getattr(root, name)
     self._translations = get_translations(translations_dir, self,
                                           categories)
     return self
Пример #5
0
    def __init__(self, invoice):
        self.invoice = invoice
        self.invoice_datetime = ConfigStore.parse_date(
            self.invoice.invoice_date)
        self.config = ConfigStore.get_configuration(when=self.invoice_datetime)

        self.translation = Translations.load('locale',
                                             locales=[self.invoice.language],
                                             domain='pyinvoice')
        self.ugettext = self.translation.ugettext
        self.format = Format(locale=self.invoice.language)
Пример #6
0
def _format_decimal(num, format=None):
    """Returns the string of a number formatted for the current language.

    Uses django's translation.get_language() to find the current language from
    the request.
    Falls back to the default language if babel does not support the current.

    """
    lang = translation.get_language()
    if not localedata.exists(lang):
        lang = settings.LANGUAGE_CODE
    locale = Locale(translation.to_locale(lang))
    return Format(locale).decimal(num, format)
Пример #7
0
def _get_format():
    lang = get_language()
    return Format(utils.get_locale_from_lang(lang))
Пример #8
0
def _get_format():
    lang = translation.get_language()
    locale = Locale(translation.to_locale(lang))
    return Format(locale)
Пример #9
0
def _get_format():
    lang = translation.get_language()
    return Format(get_locale_from_lang(lang))