Total Complexity | 6 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Coverage | 94.12% |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | 1 | import os |
|
3 | 1 | import ast |
|
4 | |||
5 | |||
6 | 1 | class Localization(): |
|
7 | """多言語化のクラス. |
||
8 | |||
9 | ・多言語化にあるプログラム群 |
||
10 | |||
11 | Args: |
||
12 | locale_var (str): ロケーション |
||
13 | NEDITOR (str): neditor.txtの値 |
||
14 | """ |
||
15 | 1 | def __init__(self, locale_var, NEDITOR): |
|
16 | 1 | path_to_locale_dir = os.path.abspath( |
|
17 | os.path.join( |
||
18 | os.getcwd(), |
||
19 | "./locale/{0}/".format(locale_var[0]) |
||
20 | ) |
||
21 | ) |
||
22 | 1 | if os.path.exists(path_to_locale_dir) is False: |
|
23 | 1 | os.makedirs(path_to_locale_dir) |
|
24 | 1 | with open( |
|
25 | "{0}/neditor.txt".format(path_to_locale_dir), |
||
26 | encoding='utf-8', |
||
27 | mode='w' |
||
28 | ) as f: |
||
29 | 1 | f.write(NEDITOR) |
|
30 | |||
31 | 1 | with open( |
|
32 | "{0}/neditor.txt".format(path_to_locale_dir), |
||
33 | encoding='utf-8' |
||
34 | ) as f: |
||
35 | 1 | l_strip = f.read() |
|
36 | |||
37 | 1 | self.dic = ast.literal_eval(l_strip) |
|
38 | |||
39 | 1 | def get_dict(self, list): |
|
40 | """翻訳結果の取得の処理. |
||
41 | |||
42 | ・翻訳結果を取得し返す。なければデフォルト値を返す。 |
||
43 | |||
44 | Args: |
||
45 | list (str): デフォルト値 |
||
46 | |||
47 | Returns: |
||
48 | str: 翻訳結果 |
||
49 | """ |
||
50 | 1 | if self.dic[list]: |
|
51 | dic = self.dic[list] |
||
52 | else: |
||
53 | 1 | dic = list |
|
54 | |||
55 | return dic |
||
56 |