Beispiel #1
0
 def test_dateLocaleMedium(self):
     assert localize(self.date, locale='en',
                     format='medium') == 'Dec 10, 2007'
     assert localize(self.date, locale='it',
                     format='medium') == '10 dic 2007'
     assert localize(self.date, locale='de',
                     format='medium') == '10.12.2007'
Beispiel #2
0
 def test_dateLocaleFull(self):
     assert localize(self.date, locale='en',
                     format='full') == 'Monday, December 10, 2007'
     assert localize(self.date, locale='it',
                     format='full') == u'lunedì 10 dicembre 2007'
     assert localize(self.date, locale='de',
                     format='full') == 'Montag, 10. Dezember 2007'
Beispiel #3
0
 def test_dateLocaleLong(self):
     assert localize(self.date, locale='en',
                     format='long') == 'December 10, 2007'
     assert localize(self.date, locale='it',
                     format='long') == '10 dicembre 2007'
     assert localize(self.date, locale='de',
                     format='long') == '10. Dezember 2007'
Beispiel #4
0
 def test_format_float(self):
     assert localize(14.234) == '14.234'
     assert localize(125.34, '000000') == '000125'
     assert localize(125.44, '000000;(0)') == '000125'
     assert localize(-125, '000000;(-0)') == '(-000125)'
     assert localize(0, '000000;(0)') == '000000'
     assert localize(0, '000000;(0);--') == '--'
     assert localize(125, 'CR 0;DB 0; NoChange') == 'CR 125'
     assert localize(-125, 'CR 0;DB 0; NoChange') == 'DB 125'
     assert localize(0, 'CR 0;DB 0;No Change') == 'No Change'
Beispiel #5
0
 def test_format_float(self):
     assert localize(14.234) == '14.234'
     assert localize(125.34, '000000') == '000125'
     assert localize(125.44, '000000;(0)') == '000125'
     assert localize(-125, '000000;(-0)') == '(-000125)'
     assert localize(0, '000000;(0)') == '000000'
     assert localize(0, '000000;(0);--') == '--'
     assert localize(125, 'CR 0;DB 0; NoChange') == 'CR 125'
     assert localize(-125, 'CR 0;DB 0; NoChange') == 'DB 125'
     assert localize(0, 'CR 0;DB 0;No Change') == 'No Change'
Beispiel #6
0
    def test_timeLocale(self):
        assert localize(self.time, locale='en', format='short') == '12:23 PM'
        assert localize(self.time, locale='it', format='short') == '12:23'
        assert localize(self.time, locale='de', format='short') == '12:23'

        assert localize(self.time, locale='en', format='medium') == '12:23:44 PM'
        assert localize(self.time, locale='it', format='medium') == '12:23:44'
        assert localize(self.time, locale='de', format='medium') == '12:23:44'

        assert localize(self.time, locale='en', format='long') == '12:23:44 PM +0000'
        assert localize(self.time, locale='it', format='long') == '12:23:44 +0000'
        assert localize(self.time, locale='de', format='long') == '12:23:44 +0000'
Beispiel #7
0
def toText(obj, locale=None, format=None, mask=None, encoding=None, currency=None):
    """Return a unicode string representing an object of any class
    
    If there are ``locale`` or ``format`` parameters Babel is used to format the value
    according to the given localization or format
    
    :param obj: the object to be transformed in a string
    :param locale: the current locale (e.g: en, en_us, it)
    :param format: TODO
    :param mask: TODO
    :param encoding: The multibyte character encoding you choose
    :param currency: TODO"""
    if hasattr(obj, '_htraverse') and format:
        return templateReplace(format,obj)
    if isinstance(obj, list) or isinstance(obj, tuple):
        return ','.join([toText(v) for v in obj])
        #what?
    if obj in (None,''): return u''
    if not (locale or format):
        result = unicode(obj)
    else:
        result = localize(obj, locale=locale, format=format, currency=currency)
        
    if mask:
        result = mask % result
    return result
Beispiel #8
0
def toText(obj,
           locale=None,
           format=None,
           mask=None,
           encoding=None,
           currency=None):
    """Return a unicode string representing an object of any class

    If there are ``locale`` or ``format`` parameters Babel is used to format the value
    according to the given localization or format

    :param obj: the object to be transformed in a string
    :param locale: the current locale (e.g: en, en_us, it)
    :param format: TODO
    :param mask: TODO
    :param encoding: The multibyte character encoding you choose
    :param currency: TODO
    """
    if hasattr(obj, '_htraverse') and format:
        return templateReplace(format, obj)
    if isinstance(obj, list) or isinstance(obj, tuple):
        return ','.join([toText(v) for v in obj])
        # what?
    if obj in (None, ''):
        return six.u('')
    if not (locale or format):
        result = six.u(str(obj))
    else:
        result = localize(obj, locale=locale, format=format, currency=currency)

    if mask:
        result = mask % result
    return result
Beispiel #9
0
def toText(obj,
           locale=None,
           format=None,
           mask=None,
           encoding=None,
           currency=None):
    """Return a unicode string representing an object of any class.
       
       If there are ``locale`` or ``format`` parameters Babel is used to format the value 
       according to the given localization or format.
       
       :param obj: the object to be transformed in a string
       :param locale: add???. Default value is ``None``
       :param format: add???. Default value is ``None``
       :param mask: add???. Default value is ``None``
       :param encoding: The multibyte character encoding you choose. Default value is ``None``
       :param currency: add???. Default value is ``None``
       :returns: a unicode string representing an object of any class
       """
    if isinstance(obj, list) or isinstance(obj, tuple):
        return ','.join([toText(v) for v in obj])
        #what?
    if obj is None: return u''
    if not (locale or format):
        result = unicode(obj)
    else:
        result = localize(obj, locale=locale, format=format, currency=currency)

    if mask:
        result = mask % result
    return result
Beispiel #10
0
def toText(obj, locale=None, format=None, mask=None, encoding=None, currency=None):
    """Return a unicode string representing an object of any class.
       
       If there are ``locale`` or ``format`` parameters Babel is used to format the value 
       according to the given localization or format.
       
       :param obj: the object to be transformed in a string
       :param locale: add???. Default value is ``None``
       :param format: add???. Default value is ``None``
       :param mask: add???. Default value is ``None``
       :param encoding: The multibyte character encoding you choose. Default value is ``None``
       :param currency: add???. Default value is ``None``
       :returns: a unicode string representing an object of any class
       """
    if isinstance(obj, list) or isinstance(obj, tuple):
        return ','.join([toText(v) for v in obj])
        #what?
    if obj is None: return u''
    if not (locale or format):
        result = unicode(obj)
    else:
        result = localize(obj, locale=locale, format=format, currency=currency)
        
    if mask:
        result = mask % result
    return result
Beispiel #11
0
 def test_format_dec_positive(self):
     x = Decimal("1239988655.45611665677")
     assert localize(x, '#.0') == '1239988655.5'
     assert localize(x, '#.0', locale='it_IT') == '1239988655,5'
     assert localize(x, '#.#') == '1239988655.5'
     assert localize(x, '#.#', locale='it_IT') == '1239988655,5'
     assert localize(x, '#.#####') == '1239988655.45612'
     assert localize(x, '#.#####', locale='it_IT') == '1239988655,45612'
     assert localize(x, '#,###.#####') == '1,239,988,655.45612'
     assert localize(x, '#,###.#####', locale='it_IT') == '1.239.988.655,45612'
Beispiel #12
0
 def test_format_dec_positive(self):
     x = Decimal("1239988655.45611665677")
     assert localize(x, '#.0') == '1239988655.5'
     assert localize(x, '#.0', locale='it_IT') == '1239988655,5'
     assert localize(x, '#.#') == '1239988655.5'
     assert localize(x, '#.#', locale='it_IT') == '1239988655,5'
     assert localize(x, '#.#####') == '1239988655.45612'
     assert localize(x, '#.#####', locale='it_IT') == '1239988655,45612'
     assert localize(x, '#,###.#####') == '1,239,988,655.45612'
     assert localize(x, '#,###.#####',
                     locale='it_IT') == '1.239.988.655,45612'
Beispiel #13
0
    def test_timeLocale(self):
        assert localize(self.time, locale='en', format='short') == '12:23 PM'
        assert localize(self.time, locale='it', format='short') == '12:23'
        assert localize(self.time, locale='de', format='short') == '12:23'

        assert localize(self.time, locale='en',
                        format='medium') == '12:23:44 PM'
        assert localize(self.time, locale='it', format='medium') == '12:23:44'
        assert localize(self.time, locale='de', format='medium') == '12:23:44'

        assert localize(self.time, locale='en',
                        format='long') == '12:23:44 PM +0000'
        assert localize(self.time, locale='it',
                        format='long') == '12:23:44 +0000'
        assert localize(self.time, locale='de',
                        format='long') == '12:23:44 +0000'
Beispiel #14
0
 def test_dateLocaleFormat(self):
     assert localize(self.date, locale='en', format="EEE MMM d 'year:'yy") == 'Mon Dec 10 year:07'
     assert localize(self.date, locale='it', format="EEE MMM d 'anno:'yy") == "lun dic 10 anno:07"
     assert localize(self.date, locale='it', format='EEEE d MMMM yyyyG') == u'lunedì 10 dicembre 2007dC'
     assert localize(self.date, locale='de', format='EEEE d MMMM yyyyG') == u'Montag 10 Dezember 2007n. Chr.'
     assert localize(self.date, locale='en', format='D yyyyG') == '344 2007AD'
     assert localize(self.date, locale='en', format='ee LLLLL yyyyG') == '01 D 2007AD'
Beispiel #15
0
 def test_dateLocaleFormat(self):
     assert localize(self.date, locale='en',
                     format="EEE MMM d 'year:'yy") == 'Mon Dec 10 year:07'
     assert localize(self.date, locale='it',
                     format="EEE MMM d 'anno:'yy") == "lun dic 10 anno:07"
     assert localize(
         self.date, locale='it',
         format='EEEE d MMMM yyyyG') == u'lunedì 10 dicembre 2007d.C.'
     assert localize(
         self.date, locale='de',
         format='EEEE d MMMM yyyyG') == u'Montag 10 Dezember 2007n. Chr.'
     assert localize(self.date, locale='en',
                     format='D yyyyG') == '344 2007AD'
     assert localize(self.date, locale='en',
                     format='ee LLLLL yyyyG') == '01 D 2007AD'
Beispiel #16
0
 def test_timeLocaleFormat(self):
     assert localize(self.time, locale='en', format='a h:m:s--A') == 'PM 12:23:44--44624059'
Beispiel #17
0
 def test_date(self):
     assert localize(self.date) == '12/10/07'
Beispiel #18
0
 def test_format_int_negative(self):
     assert localize(-12567, '00000000;-0') == '-00012567'
     assert localize(-12567, '00000000;0 -') == '00012567 -'
     assert localize(-12567, '00000000;(#)') == '(00012567)'
Beispiel #19
0
 def test_format_int_positive(self):
     assert localize(12567, '00000000') == '00012567'
     assert localize(12567, '#;(#)') == '12567'
     assert localize(1256789, "#,##0;(#)") == '1,256,789'
Beispiel #20
0
 def test_noformat_float(self):
     assert localize(12.445) == '12.445'
     assert localize(125.445, locale='it_IT') == '125,445'
Beispiel #21
0
 def test_none(self):
     assert localize(None) == ''
     assert localize(None, locale='de') == ''
     assert localize(None, locale='it') == ''
Beispiel #22
0
 def test_noformat_float(self):
     assert localize(12.445) == '12.445'
     assert localize(125.445, locale='it_IT') == '125,445'
Beispiel #23
0
 def test_format_int_negative(self):
     assert localize(-12567, '00000000;-0') == '-00012567'
     assert localize(-12567, '00000000;0 -') == '00012567 -'
     assert localize(-12567, '00000000;(#)') == '(00012567)'
Beispiel #24
0
 def test_format_int_special(self):
     assert localize(125, 'CR 0;DB 0; NoChange') == 'CR 125'
     assert localize(-125, 'CR 0;DB 0; NoChange') == 'DB 125'
     assert localize(0, 'CR 0;DB 0;No Change') == 'No Change'
Beispiel #25
0
 def test_format_int_zero(self):
     assert localize(0, '######;(#)') == '0'
     assert localize(0, '#####0;(#);-*-') == '-*-'
Beispiel #26
0
 def test_format_int_positive(self):
     assert localize(12567, '00000000') == '00012567'
     assert localize(12567, '#;(#)') == '12567'
     assert localize(1256789, "#,##0;(#)") == '1,256,789'
Beispiel #27
0
 def test_noformat_decimal(self):
     x = Decimal("1239988655.45111665677")
     assert localize(x) == '1,239,988,655.451'
     assert localize(x, locale='it_IT') == '1.239.988.655,451'
Beispiel #28
0
 def test_dateLocaleMedium(self):
     assert localize(self.date, locale='en', format='medium') == 'Dec 10, 2007'
     assert localize(self.date, locale='it', format='medium') == '10/dic/2007'
     assert localize(self.date, locale='de', format='medium') == '10.12.2007'
Beispiel #29
0
 def test_none(self):
     assert localize(None) == ''
     assert localize(None, locale='de') == ''
     assert localize(None, locale='it') == ''
Beispiel #30
0
 def test_dateLocaleShort(self):
     assert localize(self.date, locale='en') == '12/10/07'
     assert localize(self.date, locale='it') == '10/12/07'
     assert localize(self.date, locale='de') == '10.12.07'
Beispiel #31
0
 def test_noformat_int(self):
     assert localize(125) == '125'
     assert localize(125, locale='it_IT') == '125'
Beispiel #32
0
    def test_datetimeLocale(self):
        assert localize(self.datetime, locale='en',
                        format='short') == '12/10/07, 10:15 PM'
        assert localize(self.datetime, locale='it',
                        format='short') == '10/12/07, 22:15'
        assert localize(self.datetime, locale='de',
                        format='short') == '10.12.07, 22:15'

        assert localize(self.datetime, locale='en',
                        format='medium') == 'Dec 10, 2007, 10:15:36 PM'
        assert localize(self.datetime, locale='it',
                        format='medium') == '10 dic 2007, 22:15:36'
        assert localize(self.datetime, locale='de',
                        format='medium') == '10.12.2007, 22:15:36'

        assert localize(
            self.datetime, locale='en',
            format='long') == 'December 10, 2007 at 10:15:36 PM +0000'
        assert localize(self.datetime, locale='it',
                        format='long') == '10 dicembre 2007 22:15:36 +0000'
        assert localize(self.datetime, locale='de',
                        format='long') == '10. Dezember 2007 um 22:15:36 +0000'

        assert localize(
            self.datetime, locale='en', format='full'
        ) == 'Monday, December 10, 2007 at 10:15:36 PM GMT+00:00'
        assert localize(
            self.datetime, locale='it',
            format='full') == u'lunedì 10 dicembre 2007 22:15:36 GMT+00:00'
        assert localize(self.datetime, locale='de', format='full'
                        ) == u'Montag, 10. Dezember 2007 um 22:15:36 GMT+00:00'
Beispiel #33
0
 def test_format_dec_negative(self):
     x = Decimal("-1239988655.45611665677")
     assert localize(x, '#.0') == '-1239988655.5'
     assert localize(x, '#.0;(#)', locale='it_IT') == '(1239988655,5)'
     assert localize(x, '#.#;-  #') == '-  1239988655.5'
     assert localize(x, '#.#;DB #', locale='it_IT') == 'DB 1239988655,5'
Beispiel #34
0
 def test_timeLocaleFormat(self):
     assert localize(self.time, locale='en',
                     format='a h:m:s--A') == 'PM 12:23:44--44624059'
Beispiel #35
0
 def test_dateLocaleFull(self):
     assert localize(self.date, locale='en', format='full') == 'Monday, December 10, 2007'
     assert localize(self.date, locale='it', format='full') == u'lunedì 10 dicembre 2007'
     assert localize(self.date, locale='de', format='full') == 'Montag, 10. Dezember 2007'
Beispiel #36
0
 def test_noformat_int(self):
     assert localize(125) == '125'
     assert localize(125, locale='it_IT') == '125'
Beispiel #37
0
 def test_format_currency(self):
     x = Decimal("1239988655.45611665677")
     assert localize(x, u'¤ #.0', u'EUR') == u'€ 1239988655.5'
     assert localize(x, u'¤ #.0', u'$') == u'$ 1239988655.5'
     assert localize(x, u'Please pay #.#### ¤ ASAP', u'EUR', locale='it_IT') == u'Please pay 1239988655,4561 € ASAP'
Beispiel #38
0
 def test_noformat_decimal(self):
     x = Decimal("1239988655.45111665677")
     assert localize(x) == '1,239,988,655.451'
     assert localize(x, locale='it_IT') == '1.239.988.655,451'
Beispiel #39
0
    def test_datetimeLocale(self):
        assert localize(self.datetime, locale='en',
                        format='short') == '12/10/07 10:15 PM'
        assert localize(self.datetime, locale='it',
                        format='short') == '10/12/07 22.15'
        assert localize(self.datetime, locale='de',
                        format='short') == '10.12.07 22:15'

        assert localize(self.datetime, locale='en',
                        format='medium') == 'Dec 10, 2007 10:15:36 PM'
        assert localize(self.datetime, locale='it',
                        format='medium') == '10/dic/2007 22.15.36'
        assert localize(self.datetime, locale='de',
                        format='medium') == '10.12.2007 22:15:36'

        assert localize(self.datetime, locale='en',
                        format='long') == 'December 10, 2007 10:15:36 PM +0000'
        assert localize(self.datetime, locale='it',
                        format='long') == '10 dicembre 2007 22.15.36 +0000'
        assert localize(self.datetime, locale='de',
                        format='long') == '10. Dezember 2007 22:15:36 +0000'

        assert localize(
            self.datetime, locale='en', format='full'
        ) == 'Monday, December 10, 2007 10:15:36 PM World (GMT) Time'
        assert localize(
            self.datetime, locale='it',
            format='full') == u'lunedì 10 dicembre 2007 22.15.36 Mondo (GMT)'
        assert localize(
            self.datetime, locale='de',
            format='full') == u'Montag, 10. Dezember 2007 22:15:36 Welt (GMT)'
Beispiel #40
0
 def test_format_int_zero(self):
     assert localize(0, '######;(#)') == '0'
     assert localize(0, '#####0;(#);-*-') == '-*-'
Beispiel #41
0
 def test_date(self):
     assert localize(self.date) == '12/10/07'
Beispiel #42
0
 def test_format_int_special(self):
     assert localize(125, 'CR 0;DB 0; NoChange') == 'CR 125'
     assert localize(-125, 'CR 0;DB 0; NoChange') == 'DB 125'
     assert localize(0, 'CR 0;DB 0;No Change') == 'No Change'
Beispiel #43
0
 def test_dateLocaleShort(self):
     assert localize(self.date, locale='en') == '12/10/07'
     assert localize(self.date, locale='it') == '10/12/07'
     assert localize(self.date, locale='de') == '10.12.07'
Beispiel #44
0
 def test_dateLocaleLong(self):
     assert localize(self.date, locale='en', format='long') == 'December 10, 2007'
     assert localize(self.date, locale='it', format='long') == '10 dicembre 2007'
     assert localize(self.date, locale='de', format='long') == '10. Dezember 2007'
Beispiel #45
0
    def test_datetimeLocale(self):
        assert localize(self.datetime, locale='en', format='short') == '12/10/07, 10:15 PM'
        assert localize(self.datetime, locale='it', format='short') == '10/12/07 22:15'
        assert localize(self.datetime, locale='de', format='short') == '10.12.07 22:15'

        assert localize(self.datetime, locale='en', format='medium') == 'Dec 10, 2007, 10:15:36 PM'
        assert localize(self.datetime, locale='it', format='medium') == '10/dic/2007 22:15:36'
        assert localize(self.datetime, locale='de', format='medium') == '10.12.2007 22:15:36'

        assert localize(self.datetime, locale='en', format='long') == 'December 10, 2007 at 10:15:36 PM +0000'
        assert localize(self.datetime, locale='it', format='long') == '10 dicembre 2007 22:15:36 +0000'
        assert localize(self.datetime, locale='de', format='long') == '10. Dezember 2007 22:15:36 +0000'

        assert localize(self.datetime, locale='en',
                        format='full') == 'Monday, December 10, 2007 at 10:15:36 PM GMT+00:00'
        assert localize(self.datetime, locale='it', format='full') == u'lunedì 10 dicembre 2007 22:15:36 GMT+00:00'
        assert localize(self.datetime, locale='de', format='full') == u'Montag, 10. Dezember 2007 22:15:36 GMT+00:00'
Beispiel #46
0
 def test_format_currency(self):
     x = Decimal("1239988655.45611665677")
     assert localize(x, u'¤ #.0', u'EUR') == u'€ 1239988655.5'
     assert localize(x, u'¤ #.0', u'$') == u'$ 1239988655.5'
     assert localize(x, u'Please pay #.#### ¤ ASAP', u'EUR',
                     locale='it_IT') == u'Please pay 1239988655,4561 € ASAP'
Beispiel #47
0
 def test_format_dec_negative(self):
     x = Decimal("-1239988655.45611665677")
     assert localize(x, '#.0') == '-1239988655.5'
     assert localize(x, '#.0;(#)', locale='it_IT') == '(1239988655,5)'
     assert localize(x, '#.#;-  #') == '-  1239988655.5'
     assert localize(x, '#.#;DB #', locale='it_IT') == 'DB 1239988655,5'