|
@@ -1,7 +1,29 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
|
|
3
|
+import json
|
|
4
|
+
|
3
|
5
|
class MlString(object):
|
4
|
6
|
""" Handle string with translations """
|
5
|
7
|
|
6
|
|
- def __init__(self, default_str, translations = dict()):
|
7
|
|
- pass
|
|
8
|
+ def __init__(self, translations = dict()):
|
|
9
|
+ self.translations = translations
|
|
10
|
+
|
|
11
|
+ def get(self, lang):
|
|
12
|
+ if not lang in self.translations:
|
|
13
|
+ return ''
|
|
14
|
+
|
|
15
|
+ return self.translations[lang]
|
|
16
|
+
|
|
17
|
+ def set(self, lang, text):
|
|
18
|
+ self.translations[lang] = text
|
|
19
|
+
|
|
20
|
+ def __str__(self):
|
|
21
|
+ return json.dumps(self.translations)
|
|
22
|
+
|
|
23
|
+ @staticmethod
|
|
24
|
+ def load(json_string):
|
|
25
|
+ if isinstance(json_string, str) and json_string != '':
|
|
26
|
+ translations = json.loads(json_string)
|
|
27
|
+ else:
|
|
28
|
+ translations = dict()
|
|
29
|
+ return MlString(translations)
|