-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutils.py
37 lines (26 loc) · 847 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
"""utils
utils for Kepler
"""
import os
import json
from Maverick.Config import g_conf
from Maverick.Utils import unify_joinpath, safe_read
g_translation = None
def match_route(current_route, route):
if route == current_route:
return 'current'
def tr(str, locale="english"):
"""translation support
translate str according to translation file
"""
global g_translation
if g_translation is None:
path = unify_joinpath(os.path.dirname(
__file__) + '/locale', g_conf.language+".json")
g_translation = json.loads(safe_read(path) or '{}')
return g_translation.get(str, str)
def filterPrefix(url: str):
"""replace prefix with `/`, to fix Valine view counting
"""
return url.replace(g_conf.site_prefix, "/")