Skip to content

Commit

Permalink
Add Swedish [sv] localization. Fix python-pendulum#561
Browse files Browse the repository at this point in the history
  • Loading branch information
cra committed Jul 26, 2021
1 parent 411d0aa commit d1181f8
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 0 deletions.
Empty file added pendulum/locales/sv/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions pendulum/locales/sv/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


"""
sv custom locale file.
"""

translations = {
# Relative time
"ago": "{} sedan",
"from_now": "från nu {}",
"after": "{0} efter",
"before": "{0} innan",
# Date formats
"date_formats": {
"LTS": "HH:mm:ss",
"LT": "HH:mm",
"L": "YYYY-MM-DD",
"LL": "D MMMM YYYY",
"LLL": "D MMMM YYYY, HH:mm",
"LLLL": "dddd, D MMMM YYYY, HH:mm",
},
}
218 changes: 218 additions & 0 deletions pendulum/locales/sv/locale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from .custom import translations as custom_translations


"""
sv locale file.
It has been generated automatically and must not be modified directly.
"""


locale = {
'plural': lambda n: 'one' if ((n == n and ((n == 1))) and (0 == 0 and ((0 == 0)))) else 'other',
'ordinal': lambda n: 'one' if (((n % 10) == (n % 10) and (((n % 10) == 1) or ((n % 10) == 2))) and (not ((n % 100) == (n % 100) and (((n % 100) == 11) or ((n % 100) == 12))))) else 'other',
'translations': {
'days': {
'abbreviated': {
0: 'sön',
1: 'mån',
2: 'tis',
3: 'ons',
4: 'tors',
5: 'fre',
6: 'lör',
},
'narrow': {
0: 'S',
1: 'M',
2: 'T',
3: 'O',
4: 'T',
5: 'F',
6: 'L',
},
'short': {
0: 'sö',
1: 'må',
2: 'ti',
3: 'on',
4: 'to',
5: 'fr',
6: 'lö',
},
'wide': {
0: 'söndag',
1: 'måndag',
2: 'tisdag',
3: 'onsdag',
4: 'torsdag',
5: 'fredag',
6: 'lördag',
},
},
'months': {
'abbreviated': {
1: 'jan.',
2: 'feb.',
3: 'mars',
4: 'apr.',
5: 'maj',
6: 'juni',
7: 'juli',
8: 'aug.',
9: 'sep.',
10: 'okt.',
11: 'nov.',
12: 'dec.',
},
'narrow': {
1: 'J',
2: 'F',
3: 'M',
4: 'A',
5: 'M',
6: 'J',
7: 'J',
8: 'A',
9: 'S',
10: 'O',
11: 'N',
12: 'D',
},
'wide': {
1: 'januari',
2: 'februari',
3: 'mars',
4: 'april',
5: 'maj',
6: 'juni',
7: 'juli',
8: 'augusti',
9: 'september',
10: 'oktober',
11: 'november',
12: 'december',
},
},
'units': {
'year': {
'one': '{0} år',
'other': '{0} år',
},
'month': {
'one': '{0} månad',
'other': '{0} månader',
},
'week': {
'one': '{0} vecka',
'other': '{0} veckor',
},
'day': {
'one': '{0} dygn',
'other': '{0} dygn',
},
'hour': {
'one': '{0} timme',
'other': '{0} timmar',
},
'minute': {
'one': '{0} minut',
'other': '{0} minuter',
},
'second': {
'one': '{0} sekund',
'other': '{0} sekunder',
},
'microsecond': {
'one': '{0} mikrosekund',
'other': '{0} mikrosekunder',
},
},
'relative': {
'year': {
'future': {
'other': 'om {0} år',
'one': 'om {0} år',
},
'past': {
'other': 'för {0} år sedan',
'one': 'för {0} år sedan',
},
},
'month': {
'future': {
'other': 'om {0} månader',
'one': 'om {0} månad',
},
'past': {
'other': 'för {0} månader sedan',
'one': 'för {0} månad sedan',
},
},
'week': {
'future': {
'other': 'om {0} veckor',
'one': 'om {0} vecka',
},
'past': {
'other': 'för {0} veckor sedan',
'one': 'för {0} vecka sedan',
},
},
'day': {
'future': {
'other': 'om {0} dagar',
'one': 'om {0} dag',
},
'past': {
'other': 'för {0} dagar sedan',
'one': 'för {0} dag sedan',
},
},
'hour': {
'future': {
'other': 'om {0} timmar',
'one': 'om {0} timme',
},
'past': {
'other': 'för {0} timmar sedan',
'one': 'för {0} timme sedan',
},
},
'minute': {
'future': {
'other': 'om {0} minuter',
'one': 'om {0} minut',
},
'past': {
'other': 'för {0} minuter sedan',
'one': 'för {0} minut sedan',
},
},
'second': {
'future': {
'other': 'om {0} sekunder',
'one': 'om {0} sekund',
},
'past': {
'other': 'för {0} sekunder sedan',
'one': 'för {0} sekund sedan',
},
},
},
'day_periods': {
'midnight': 'midnatt',
'am': 'fm',
'pm': 'em',
'morning1': 'på morgonen',
'morning2': 'på förmiddagen',
'afternoon1': 'på eftermiddagen',
'evening1': 'på kvällen',
'night1': 'på natten',
},
},
'custom': custom_translations
}
88 changes: 88 additions & 0 deletions tests/localization/test_sv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import pendulum


locale = "sv"


def test_diff_for_humans():
with pendulum.test(pendulum.datetime(2016, 8, 29)):
diff_for_humans()


def diff_for_humans():
d = pendulum.now().subtract(seconds=1)
assert d.diff_for_humans(locale=locale) == "för 1 sekund sedan"

d = pendulum.now().subtract(seconds=2)
assert d.diff_for_humans(locale=locale) == "för 2 sekunder sedan"

d = pendulum.now().subtract(seconds=5)
assert d.diff_for_humans(locale=locale) == "för 5 sekunder sedan"

d = pendulum.now().subtract(seconds=21)
assert d.diff_for_humans(locale=locale) == "för 21 sekunder sedan"

d = pendulum.now().subtract(minutes=1)
assert d.diff_for_humans(locale=locale) == "för 1 minut sedan"

d = pendulum.now().subtract(minutes=2)
assert d.diff_for_humans(locale=locale) == "för 2 minuter sedan"

d = pendulum.now().subtract(minutes=5)
assert d.diff_for_humans(locale=locale) == "för 5 minuter sedan"

d = pendulum.now().subtract(hours=1)
assert d.diff_for_humans(locale=locale) == "för 1 timme sedan"

d = pendulum.now().subtract(hours=2)
assert d.diff_for_humans(locale=locale) == "för 2 timmar sedan"

d = pendulum.now().subtract(hours=5)
assert d.diff_for_humans(locale=locale) == "för 5 timmar sedan"

d = pendulum.now().subtract(days=1)
assert d.diff_for_humans(locale=locale) == "för 1 dag sedan"

d = pendulum.now().subtract(days=2)
assert d.diff_for_humans(locale=locale) == "för 2 dagar sedan"

d = pendulum.now().subtract(days=5)
assert d.diff_for_humans(locale=locale) == "för 5 dagar sedan"

d = pendulum.now().subtract(weeks=1)
assert d.diff_for_humans(locale=locale) == "för 1 vecka sedan"

d = pendulum.now().subtract(weeks=2)
assert d.diff_for_humans(locale=locale) == "för 2 veckor sedan"

d = pendulum.now().subtract(months=1)
assert d.diff_for_humans(locale=locale) == "för 1 månad sedan"

d = pendulum.now().subtract(months=2)
assert d.diff_for_humans(locale=locale) == "för 2 månader sedan"

d = pendulum.now().subtract(months=5)
assert d.diff_for_humans(locale=locale) == "för 5 månader sedan"

d = pendulum.now().subtract(years=1)
assert d.diff_for_humans(locale=locale) == "för 1 år sedan"

d = pendulum.now().subtract(years=2)
assert d.diff_for_humans(locale=locale) == "för 2 år sedan"

d = pendulum.now().subtract(years=5)
assert d.diff_for_humans(locale=locale) == "för 5 år sedan"

d = pendulum.now().add(seconds=1)
assert d.diff_for_humans(locale=locale) == "om 1 sekund"

d = pendulum.now().add(seconds=1)
d2 = pendulum.now()
assert d.diff_for_humans(d2, locale=locale) == "1 sekund efter"
assert d2.diff_for_humans(d, locale=locale) == "1 sekund innan"

assert d.diff_for_humans(d2, True, locale=locale) == "1 sekund"
assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == "2 sekunder"

0 comments on commit d1181f8

Please sign in to comment.