xu-song commited on
Commit
1aaa002
1 Parent(s): 0aebd8b
Files changed (1) hide show
  1. utils/i18n_util.py +26 -0
utils/i18n_util.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def get_lang(request: gr.Request):
5
+ """
6
+ 'accept-language', b'zh,en;q=0.9,zh-CN;q=0.8')
7
+ """
8
+ accept_language = None
9
+ langs = []
10
+ try:
11
+ accept_language = request.headers["Accept-Language"]
12
+ for lang in accept_language.split(",")[:5]:
13
+ lang = lang.lower()
14
+ if lang.startswith("en"):
15
+ langs.append("en")
16
+ elif lang.startswith("es"):
17
+ langs.append("es")
18
+ elif lang.startswith("zh"):
19
+ langs.append("zh")
20
+ elif lang.startswith("fr"):
21
+ langs.append("fr")
22
+ elif lang.startswith("de"):
23
+ langs.append("de")
24
+ except Exception as e:
25
+ print(e)
26
+ return accept_language, langs