-
Notifications
You must be signed in to change notification settings - Fork 16
/
model_i18n.py
89 lines (73 loc) · 2.57 KB
/
model_i18n.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from collections import namedtuple
from flask_babel import gettext
import copy
EN_US_KEY = "en_us"
ES_MX_KEY = "es_mx"
Lang = namedtuple('Lang', ['value', 'display_text'])
LANGUAGES = {
EN_US_KEY: Lang("en_US", "English"),
ES_MX_KEY: Lang("es_MX", "Español")
}
def translate_sample(sample):
i18n_sample = copy.deepcopy(sample)
i18n_sample["sample_site"] = gettext(sample["sample_site"])
if i18n_sample["sample_site"] is None:
i18n_sample["sample_site"] = ""
if i18n_sample["sample_datetime"] is None:
i18n_sample["sample_datetime"] = ""
return i18n_sample
def translate_source(source):
i18n_source = copy.deepcopy(source)
i18n_source["source_type"] = gettext(source["source_type"])
return i18n_source
def translate_survey_template(survey_template):
i18n_survey_template = copy.deepcopy(survey_template)
i18n_survey_template["survey_template_title"] = \
gettext(survey_template["survey_template_title"])
return i18n_survey_template
def declare_enum_values():
# There are a few enum fields in the private api
# model object types that need to be translated
# We define those enum values here so that babel
# picks them up for translation.
# Sample.sample_site
# sample_site:
# enum: ["Blood (skin prick)", "Saliva", "Ear wax", "Forehead",
# "Fur", "Hair", "Left hand", "Left leg", "Mouth", "Nares",
# "Nasal mucus", "Right hand", "Right leg", "Stool", "Tears",
# "Torso", "Vaginal mucus", null]
gettext("Blood (skin prick)")
gettext("Saliva")
gettext("Ear wax")
gettext("Forehead")
gettext("Fur")
gettext("Hair")
gettext("Left hand")
gettext("Left leg")
gettext("Mouth")
gettext("Nares")
gettext("Nasal mucus")
gettext("Right hand")
gettext("Right leg")
gettext("Stool")
gettext("Tears")
gettext("Torso")
gettext("Vaginal mucus")
# Source.source_site:
# source_type:
# enum: [human, animal, environmental]
gettext("human")
gettext("animal")
gettext("environmental")
# SurveyTemplate.survey_template_title:
# Not defined in the microsetta-private-api yaml at the moment
# Taken from survey_template_repo.py
gettext("Primary Questionnaire")
gettext("Pet Information")
gettext("Fermented Foods Questionnaire")
gettext("Surfer Questionnaire")
gettext("Personal Microbiome Information")
gettext("COVID-19 Questionnaire")
gettext("Vioscreen Food Frequency Questionnaire")
# Ensure that EN_US_KEY is added to the POT file
gettext("en_us")