Total Complexity | 6 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 93.33% |
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 | FILE_NAME (str): ファイル名 |
||
14 | TRANSLATION_DATA (str): 翻訳データ |
||
15 | """ |
||
16 | 1 | ||
17 | 1 | def __init__(self, locale_var, FILE_NAME, TRANSLATION_DATA): |
|
18 | path_to_locale_dir = os.path.abspath( |
||
19 | os.path.join(os.getcwd(), "./locale/{0}/".format(locale_var[0])) |
||
20 | ) |
||
21 | if os.path.exists(path_to_locale_dir) is False: |
||
22 | os.makedirs(path_to_locale_dir) |
||
23 | 1 | with open( |
|
24 | 1 | "{0}/{1}".format(path_to_locale_dir, FILE_NAME), |
|
25 | 1 | encoding="utf-8", |
|
26 | mode="w", |
||
27 | ) as f: |
||
28 | f.write(TRANSLATION_DATA) |
||
29 | |||
30 | 1 | with open( |
|
31 | "{0}/{1}".format(path_to_locale_dir, FILE_NAME), encoding="utf-8" |
||
32 | 1 | ) as f: |
|
33 | l_strip = f.read() |
||
34 | |||
35 | self.dic = ast.literal_eval(l_strip) |
||
36 | 1 | ||
37 | def get_dict(self, list): |
||
38 | 1 | """翻訳結果の取得の処理. |
|
39 | |||
40 | 1 | ・翻訳結果を取得し返す。なければデフォルト値を返す。 |
|
41 | |||
42 | Args: |
||
43 | list (str): デフォルト値 |
||
44 | |||
45 | Returns: |
||
46 | str: 翻訳結果 |
||
47 | """ |
||
48 | if self.dic[list]: |
||
49 | dic = self.dic[list] |
||
50 | else: |
||
51 | 1 | dic = list |
|
52 | |||
53 | return dic |
||
54 |