1 from mygpo
.api
.models
import Podcast
2 from babel
import Locale
, UnknownLocaleError
5 def get_accepted_lang(request
):
6 return list(set([s
[:2] for s
in request
.META
.get('HTTP_ACCEPT_LANGUAGE', '').split(',')]))
8 def get_podcast_languages():
10 Returns all 2-letter language codes that are used by podcasts.
12 It filters obviously invalid strings, but does not check if any
13 of these codes is contained in ISO 639.
16 r
= '^[a-zA-Z]{2}[-_]?.*$'
18 langs
= [x
['language'] for x
in Podcast
.objects
.values('language').distinct()]
19 sane_lang
= list(set([l
[:2] for l
in langs
if l
and re
.match(r
, l
)]))
25 def get_language_names(lang
):
27 Takes a list of language codes and returns a list of tuples
34 except UnknownLocaleError
:
37 if locale
.display_name
:
38 res
[l
] = locale
.display_name
43 class UpdatedException(Exception):
44 """Base exception with additional payload"""
45 def __init__(self
, data
):
46 Exception.__init
__(self
)