Ticket #3925: localflavor_sk_2.diff

File localflavor_sk_2.diff, 10.2 KB (added by Martin Kosír <martin@…>, 18 years ago)

More translation-friendly patch.

  • django/contrib/localflavor/sk/sk_regions.py

    Property changes on: django/contrib/localflavor/sk
    ___________________________________________________________________
    Name: svn:ignore
       + *.pyc
    
    
     
     1"""
     2Slovak regions according to http://sk.wikipedia.org/wiki/Administrat%C3%ADvne_%C4%8Dlenenie_Slovenska
     3"""
     4
     5from django.utils.translation import gettext_lazy as _
     6
     7REGION_CHOICES = (
     8    ('BB', _('Banska Bystrica region')),
     9    ('BA', _('Bratislava region')),
     10    ('KE', _('Kosice region')),
     11    ('NR', _('Nitra region')),
     12    ('PO', _('Presov region')),
     13    ('TN', _('Trencin region')),
     14    ('TT', _('Trnava region')),
     15    ('ZA', _('Zilina region')),
     16)
     17 No newline at end of file
  • django/contrib/localflavor/sk/sk_districts.py

     
     1"""
     2Slovak districts according to http://sk.wikipedia.org/wiki/Administrat%C3%ADvne_%C4%8Dlenenie_Slovenska
     3"""
     4
     5from django.utils.translation import gettext_lazy as _
     6
     7DISTRICT_CHOICES = (
     8    ('BB', _('Banska Bystrica')),
     9    ('BS', _('Banska Stiavnica')),
     10    ('BJ', _('Bardejov')),
     11    ('BN', _('Banovce nad Bebravou')),
     12    ('BR', _('Brezno')),
     13    ('BA1', _('Bratislava I')),
     14    ('BA2', _('Bratislava II')),
     15    ('BA3', _('Bratislava III')),
     16    ('BA4', _('Bratislava IV')),
     17    ('BA5', _('Bratislava V')),
     18    ('BY', _('Bytca')),
     19    ('CA', _('Cadca')),
     20    ('DT', _('Detva')),
     21    ('DK', _('Dolny Kubin')),
     22    ('DS', _('Dunajska Streda')),
     23    ('GA', _('Galanta')),
     24    ('GL', _('Gelnica')),
     25    ('HC', _('Hlohovec')),
     26    ('HE', _('Humenne')),
     27    ('IL', _('Ilava')),
     28    ('KK', _('Kezmarok')),
     29    ('KN', _('Komarno')),
     30    ('KE1', _('Kosice I')),
     31    ('KE2', _('Kosice II')),
     32    ('KE3', _('Kosice III')),
     33    ('KE4', _('Kosice IV')),
     34    ('KEO', _('Kosice - okolie')),
     35    ('KA', _('Krupina')),
     36    ('KM', _('Kysucke Nove Mesto')),
     37    ('LV', _('Levice')),
     38    ('LE', _('Levoca')),
     39    ('LM', _('Liptovsky Mikulas')),
     40    ('LC', _('Lucenec')),
     41    ('MA', _('Malacky')),
     42    ('MT', _('Martin')),
     43    ('ML', _('Medzilaborce')),
     44    ('MI', _('Michalovce')),
     45    ('MY', _('Myjava')),
     46    ('NO', _('Namestovo')),
     47    ('NR', _('Nitra')),
     48    ('NM', _('Nove Mesto nad Vahom')),
     49    ('NZ', _('Nove Zamky')),
     50    ('PE', _('Partizanske')),
     51    ('PK', _('Pezinok')),
     52    ('PN', _('Piestany')),
     53    ('PT', _('Poltar')),
     54    ('PP', _('Poprad')),
     55    ('PB', _('Povazska Bystrica')),
     56    ('PO', _('Presov')),
     57    ('PD', _('Prievidza')),
     58    ('PU', _('Puchov')),
     59    ('RA', _('Revuca')),
     60    ('RS', _('Rimavska Sobota')),
     61    ('RV', _('Roznava')),
     62    ('RK', _('Ruzomberok')),
     63    ('SB', _('Sabinov')),
     64    ('SC', _('Senec')),
     65    ('SE', _('Senica')),
     66    ('SI', _('Skalica')),
     67    ('SV', _('Snina')),
     68    ('SO', _('Sobrance')),
     69    ('SN', _('Spisska Nova Ves')),
     70    ('SL', _('Stara Lubovna')),
     71    ('SP', _('Stropkov')),
     72    ('SK', _('Svidnik')),
     73    ('SA', _('Sala')),
     74    ('TO', _('Topolcany')),
     75    ('TV', _('Trebisov')),
     76    ('TN', _('Trencin')),
     77    ('TT', _('Trnava')),
     78    ('TR', _('Turcianske Teplice')),
     79    ('TS', _('Tvrdosin')),
     80    ('VK', _('Velky Krtis')),
     81    ('VT', _('Vranov nad Toplou')),
     82    ('ZM', _('Zlate Moravce')),
     83    ('ZV', _('Zvolen')),
     84    ('ZC', _('Zarnovica')),
     85    ('ZH', _('Ziar nad Hronom')),
     86    ('ZA', _('Zilina')),
     87)
  • django/contrib/localflavor/sk/forms.py

     
     1"""
     2Slovak-specific form helpers
     3"""
     4
     5from django.newforms.fields import Select, RegexField
     6from django.utils.translation import gettext
     7
     8class SKRegionSelect(Select):
     9    """
     10    A select widget widget with list of Slovak regions as choices.
     11    """
     12    def __init__(self, attrs=None):
     13        from sk_regions import REGION_CHOICES
     14        super(SKRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
     15       
     16class SKDistrictSelect(Select):
     17    """
     18    A select widget with list of Slovak districts as choices.
     19    """
     20    def __init__(self, attrs=None):
     21        from sk_districts import DISTRICT_CHOICES
     22        super(SKDistrictSelect, self).__init__(attrs, choices=DISTRICT_CHOICES)
     23       
     24class SKPostalCodeField(RegexField):
     25    """
     26    A form field that validates its input as Slovak postal code.
     27    Valid form is XXXXX or XXX XX, where X represents integer.
     28    """
     29    def __init__(self, *args, **kwargs):
     30        super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
     31            max_length=None, min_length=None,
     32            error_message=gettext(u'Enter a postal code in the format XXXXX or XXX XX.'),
     33            *args, **kwargs)
     34
     35    def clean(self, value):
     36        """
     37        Validates the input and returns a string that contains only numbers.
     38        Returns an empty string for empty values.
     39        """
     40        v = super(SKPostalCodeField, self).clean(value)
     41        return v.replace(' ', '')
     42 No newline at end of file
  • tests/regressiontests/forms/localflavor.py

     
    882882Traceback (most recent call last):
    883883...
    884884ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format']
     885
     886
     887# SKPostalCodeField #########################################################
     888
     889>>> from django.contrib.localflavor.sk.forms import SKPostalCodeField
     890>>> f = SKPostalCodeField()
     891>>> f.clean('84545x')
     892Traceback (most recent call last):
     893...
     894ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
     895>>> f.clean('91909')
     896u'91909'
     897>>> f.clean('917 01')
     898u'91701'
     899
     900# SKRegionSelect ############################################################
     901
     902>>> from django.contrib.localflavor.sk.forms import SKRegionSelect
     903>>> w = SKRegionSelect()
     904>>> w.render('regions', 'TT')
     905u'<select name="regions">\n<option value="BB">Banska Bystrica region</option>\n<option value="BA">Bratislava region</option>\n<option value="KE">Kosice region</option>\n<option value="NR">Nitra region</option>\n<option value="PO">Presov region</option>\n<option value="TN">Trencin region</option>\n<option value="TT" selected="selected">Trnava region</option>\n<option value="ZA">Zilina region</option>\n</select>'
     906
     907# SKDistrictSelect ##########################################################
     908
     909>>> from django.contrib.localflavor.sk.forms import SKDistrictSelect
     910>>> w = SKDistrictSelect()
     911>>> w.render('Districts', 'RK')
     912u'<select name="Districts">\n<option value="BB">Banska Bystrica</option>\n<option value="BS">Banska Stiavnica</option>\n<option value="BJ">Bardejov</option>\n<option value="BN">Banovce nad Bebravou</option>\n<option value="BR">Brezno</option>\n<option value="BA1">Bratislava I</option>\n<option value="BA2">Bratislava II</option>\n<option value="BA3">Bratislava III</option>\n<option value="BA4">Bratislava IV</option>\n<option value="BA5">Bratislava V</option>\n<option value="BY">Bytca</option>\n<option value="CA">Cadca</option>\n<option value="DT">Detva</option>\n<option value="DK">Dolny Kubin</option>\n<option value="DS">Dunajska Streda</option>\n<option value="GA">Galanta</option>\n<option value="GL">Gelnica</option>\n<option value="HC">Hlohovec</option>\n<option value="HE">Humenne</option>\n<option value="IL">Ilava</option>\n<option value="KK">Kezmarok</option>\n<option value="KN">Komarno</option>\n<option value="KE1">Kosice I</option>\n<option value="KE2">Kosice II</option>\n<option value="KE3">Kosice III</option>\n<option value="KE4">Kosice IV</option>\n<option value="KEO">Kosice - okolie</option>\n<option value="KA">Krupina</option>\n<option value="KM">Kysucke Nove Mesto</option>\n<option value="LV">Levice</option>\n<option value="LE">Levoca</option>\n<option value="LM">Liptovsky Mikulas</option>\n<option value="LC">Lucenec</option>\n<option value="MA">Malacky</option>\n<option value="MT">Martin</option>\n<option value="ML">Medzilaborce</option>\n<option value="MI">Michalovce</option>\n<option value="MY">Myjava</option>\n<option value="NO">Namestovo</option>\n<option value="NR">Nitra</option>\n<option value="NM">Nove Mesto nad Vahom</option>\n<option value="NZ">Nove Zamky</option>\n<option value="PE">Partizanske</option>\n<option value="PK">Pezinok</option>\n<option value="PN">Piestany</option>\n<option value="PT">Poltar</option>\n<option value="PP">Poprad</option>\n<option value="PB">Povazska Bystrica</option>\n<option value="PO">Presov</option>\n<option value="PD">Prievidza</option>\n<option value="PU">Puchov</option>\n<option value="RA">Revuca</option>\n<option value="RS">Rimavska Sobota</option>\n<option value="RV">Roznava</option>\n<option value="RK" selected="selected">Ruzomberok</option>\n<option value="SB">Sabinov</option>\n<option value="SC">Senec</option>\n<option value="SE">Senica</option>\n<option value="SI">Skalica</option>\n<option value="SV">Snina</option>\n<option value="SO">Sobrance</option>\n<option value="SN">Spisska Nova Ves</option>\n<option value="SL">Stara Lubovna</option>\n<option value="SP">Stropkov</option>\n<option value="SK">Svidnik</option>\n<option value="SA">Sala</option>\n<option value="TO">Topolcany</option>\n<option value="TV">Trebisov</option>\n<option value="TN">Trencin</option>\n<option value="TT">Trnava</option>\n<option value="TR">Turcianske Teplice</option>\n<option value="TS">Tvrdosin</option>\n<option value="VK">Velky Krtis</option>\n<option value="VT">Vranov nad Toplou</option>\n<option value="ZM">Zlate Moravce</option>\n<option value="ZV">Zvolen</option>\n<option value="ZC">Zarnovica</option>\n<option value="ZH">Ziar nad Hronom</option>\n<option value="ZA">Zilina</option>\n</select>'
     913
    885914"""
     915
     916
     917
Back to Top