Passed
Push — master ( 1d2121...eed8cd )
by Yoshihiro
02:50
created

i18n.llize.Localization.__init__()   A

Complexity

Conditions 4

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 19
nop 3
dl 0
loc 23
ccs 9
cts 9
cp 1
crap 4
rs 9.45
c 0
b 0
f 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