5353 QgistTypeError ,
5454 QgistValueError ,
5555 )
56+ from .util import translate
5657
5758
5859# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -63,19 +64,19 @@ def get_config_path():
6364
6465 root_fld = QgsApplication .qgisSettingsDirPath ()
6566 if os .path .exists (root_fld ) and not os .path .isdir (root_fld ):
66- raise QgistValueError (' qgis settings path does not point to a directory' )
67+ raise QgistValueError (translate ( 'global' , ' qgis settings path does not point to a directory') )
6768 if not os .path .exists (root_fld ):
68- raise QgistValueError (' qgis settings path does not exist' ) # TODO create?
69+ raise QgistValueError (translate ( 'global' , ' qgis settings path does not exist') ) # TODO create?
6970
7071 root_qgis_fld = os .path .join (root_fld , QGIS_CONFIG_FLD )
7172 if os .path .exists (root_qgis_fld ) and not os .path .isdir (root_qgis_fld ):
72- raise QgistValueError (' qgis plugin configuration path exists but is not a directory' )
73+ raise QgistValueError (translate ( 'global' , ' qgis plugin configuration path exists but is not a directory') )
7374 if not os .path .exists (root_qgis_fld ):
7475 os .mkdir (root_qgis_fld )
7576
7677 root_qgis_qgist_fld = os .path .join (root_qgis_fld , QGIST_CONFIG_FLD )
7778 if os .path .exists (root_qgis_qgist_fld ) and not os .path .isdir (root_qgis_qgist_fld ):
78- raise QgistValueError (' qgist configuration path exists but is not a directory' )
79+ raise QgistValueError (translate ( 'global' , ' qgist configuration path exists but is not a directory') )
7980 if not os .path .exists (root_qgis_qgist_fld ):
8081 os .mkdir (root_qgis_qgist_fld )
8182
@@ -91,40 +92,40 @@ class config_class:
9192 def __init__ (self , fn ):
9293
9394 if not isinstance (fn , str ):
94- raise QgistTypeError (' fn must be str' )
95+ raise QgistTypeError (translate ( 'global' , ' fn must be str') )
9596
9697 self ._fn = fn
9798
9899 if not os .path .exists (fn ):
99100 if not os .path .exists (os .path .dirname (fn )):
100- raise QgistValueError (' parent of fn must exists' )
101+ raise QgistValueError (translate ( 'global' , ' parent of fn must exists') )
101102 if not os .path .isdir (os .path .dirname (fn )):
102- raise QgistValueError (' parent of fn must be a directory' )
103+ raise QgistValueError (translate ( 'global' , ' parent of fn must be a directory') )
103104 self ._data = {}
104105 self ._save ()
105106 else :
106107 if not os .path .isfile (fn ):
107- raise QgistValueError (' fn must be a file' )
108+ raise QgistValueError (translate ( 'global' , ' fn must be a file') )
108109 with open (fn , 'r' , encoding = 'utf-8' ) as f :
109110 self ._data = json .loads (f .read ())
110111 if not isinstance (self ._data , dict ):
111- raise QgistTypeError (' configuration data must be a dict' )
112+ raise QgistTypeError (translate ( 'global' , ' configuration data must be a dict') )
112113
113114 def __getitem__ (self , name ):
114115
115116 if not isinstance (name , str ):
116- raise QgistTypeError (' name must be str' )
117+ raise QgistTypeError (translate ( 'global' , ' name must be str') )
117118 if name not in self ._data .keys ():
118- raise QgistConfigKeyError (' unknown configuration field name' )
119+ raise QgistConfigKeyError (translate ( 'global' , ' unknown configuration field name') )
119120
120121 return copy .deepcopy (self ._data [name ])
121122
122123 def __setitem__ (self , name , value ):
123124
124125 if not isinstance (name , str ):
125- raise QgistTypeError (' name must be str' )
126+ raise QgistTypeError (translate ( 'global' , ' name must be str') )
126127 if not config_class ._check_value (value ):
127- raise QgistTypeError (' value contains not allowed types' )
128+ raise QgistTypeError (translate ( 'global' , ' value contains not allowed types') )
128129
129130 self ._data [name ] = value
130131 self ._save ()
@@ -170,7 +171,7 @@ def _save(self):
170171 break
171172 attempt += 1
172173 if not attempt_ok :
173- raise QgistValueError (' could not backup old configuration before saving new - too many old backups' )
174+ raise QgistValueError (translate ( 'global' , ' could not backup old configuration before saving new - too many old backups') )
174175 os .rename (self ._fn , backup_fn )
175176
176177 with open (self ._fn , 'w' , encoding = 'utf-8' ) as f :
0 commit comments