@@ -56,49 +56,55 @@ def __init__(self, include=(), load_mode=LoadMode.REALTIME):
56
56
self .__m_default_source_lang = None
57
57
self .__m_default_target_lang = None
58
58
59
- if len (include ) != 0 :
59
+ # Avoid parsing a tuple with only one element as a single string.
60
+ if isinstance (include , tuple ):
60
61
for expression in include :
61
- """
62
- Parses expressions imported into language dictionaries via param<include>.
62
+ self .__parse_expression (expression )
63
+ else :
64
+ self .__parse_expression (include )
63
65
64
- There are two forms of this expression, one is full and the other is short.
66
+ # One-time loading mode.
67
+ if self ._m_load_mode == LoadMode .ONETIME :
68
+ self .__load_lang_dict ()
65
69
66
- For example:
70
+ def __parse_expression (self ,expression ):
71
+ """
72
+ Parses expressions imported into language dictionaries via param<include>.
73
+
74
+ There are two forms of this expression, one is full and the other is short.
67
75
68
- 1. ``full``: './en_us.lang as en_us'
69
- 2. ``short``: './en_us.lang'
76
+ For example:
70
77
71
- Note that when using the short form, the name of the associated language will be the name of the file.
78
+ 1. ``full``: './en_us.lang as en_us'
79
+ 2. ``short``: './en_us.lang'
80
+
81
+ Note that when using the short form, the name of the associated language will be the name of the file.
82
+ """
83
+ if expression .find ("as" ) != - 1 :
84
+ if expression .count ("as" ) == 1 :
72
85
"""
73
- if expression .find ("as" ) != - 1 :
74
- if expression .count ("as" ) == 1 :
75
- """
76
- A list of strings representing the distinct terms of the expression after it is parsed.
77
-
78
- - ``expression_parsing[0]``: The file path of the language dictionary.
79
- - ``expression_parsing[1]``: The associated language of the language dictionary.
80
- """
81
- expression_parsing = [expression_unit .strip () for expression_unit in expression .split ("as" )]
82
- dictionary_file = File (expression_parsing [0 ], False , False )
83
- dictionary_associated_lang = expression_parsing [1 ]
84
- else :
85
- raise ExpressionError (expression )
86
- else :
87
- dictionary_file = File (expression , False , False )
88
- dictionary_associated_lang = dictionary_file .info ["name" ]
86
+ A list of strings representing the distinct terms of the expression after it is parsed.
89
87
90
- # Store language dictionary file information for different languages into member:private<self.__m_dict>.
91
- if not dictionary_file .state ["exist" ]:
92
- raise FileNotFoundError ("Language dictionary not found: " + dictionary_file .info ["path" ])
93
- else :
94
- if dictionary_associated_lang in self .__m_dict .keys ():
95
- self .__m_dict [dictionary_associated_lang ].append (dictionary_file .info ["path" ])
96
- else :
97
- self .__m_dict [dictionary_associated_lang ] = [dictionary_file .info ["path" ]]
88
+ - ``expression_parsing[0]``: The file path of the language dictionary.
89
+ - ``expression_parsing[1]``: The associated language of the language dictionary.
90
+ """
91
+ expression_parsing = [expression_unit .strip () for expression_unit in expression .split ("as" )]
92
+ dictionary_file = File (expression_parsing [0 ], False , False )
93
+ dictionary_associated_lang = expression_parsing [1 ]
94
+ else :
95
+ raise ExpressionError (expression )
96
+ else :
97
+ dictionary_file = File (expression , False , False )
98
+ dictionary_associated_lang = dictionary_file .info ["name" ]
98
99
99
- # One-time loading mode.
100
- if self ._m_load_mode == LoadMode .ONETIME :
101
- self .__load_lang_dict ()
100
+ # Store language dictionary file information for different languages into member:private<self.__m_dict>.
101
+ if not dictionary_file .state ["exist" ]:
102
+ raise FileNotFoundError ("Language dictionary not found: " + dictionary_file .info ["path" ])
103
+ else :
104
+ if dictionary_associated_lang in self .__m_dict .keys ():
105
+ self .__m_dict [dictionary_associated_lang ].append (dictionary_file .info ["path" ])
106
+ else :
107
+ self .__m_dict [dictionary_associated_lang ] = [dictionary_file .info ["path" ]]
102
108
103
109
def __load_lang_dict (self ):
104
110
new_dict = self .__m_dict .copy ()
0 commit comments