Debian Codegraph @

src/timeago/locales/__init__.py

raw symbols SCIP
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 '''
4 Created on 2016-5-26
5
6 @author: hustcc
7 '''
8 from __future__ import absolute_import
9
10 from timeago import setting
11
12
13 def locale_module(mod, locale):
14 try:
15 return getattr(getattr(getattr(mod, 'locales'), locale), 'LOCALE')
16 except:
17 raise
18
19
20 def timeago_template(locale, index, ago_in):
21 '''
22 simple locale implement
23 '''
24 try:
25 LOCALE = __import__('timeago.locales.' + locale)
26 LOCALE = locale_module(LOCALE, locale)
27 except:
28 locale = setting.DEFAULT_LOCALE
29 LOCALE = __import__('timeago.locales.' + locale)
30 LOCALE = locale_module(LOCALE, locale)
31
32 if isinstance(LOCALE, list):
33 return LOCALE[index][ago_in]
34 else:
35 return LOCALE(index, ago_in)