@@ -145,6 +145,11 @@ def set_locale(locale):
145
145
146
146
147
147
def _normalize_locale (locale ):
148
+ # depending on the environment, the provided locale will also contain a charmap
149
+ # (e.g. 'en_US.UTF-8 UTF-8' instead of only the locale 'en_US.UTF-8')
150
+ # drop the charmap
151
+ locale = locale .split ()[0 ]
152
+
148
153
lang_encoding = locale .split ('.' )
149
154
lang_split = lang_encoding [0 ].split ('_' )
150
155
if len (lang_split ) > 1 :
@@ -183,16 +188,32 @@ def gen_locale(locale):
183
188
184
189
salt '*' locale.gen_locale 'en_US.UTF-8'
185
190
'''
186
- if __grains__ .get ('os' ) == 'Debian' :
191
+ # validate the supplied locale
192
+ valid = __salt__ ['file.replace' ](
193
+ '/usr/share/i18n/SUPPORTED' ,
194
+ '^{0}$' .format (locale ),
195
+ '^{0}$' .format (locale ),
196
+ search_only = True
197
+ )
198
+ if not valid :
199
+ log .error ('The provided locale "{0}" is invalid' .format (locale ))
200
+ return False
201
+
202
+ if __grains__ .get ('os' ) == 'Debian' or __grains__ .get ('os_family' ) == 'Gentoo' :
187
203
__salt__ ['file.replace' ](
188
204
'/etc/locale.gen' ,
189
205
'# {0} ' .format (locale ),
190
206
'{0} ' .format (locale ),
191
207
append_if_not_found = True
192
208
)
193
209
194
- __salt__ ['cmd.run' ](
195
- 'locale-gen {0}' .format (locale )
196
- )
210
+ if __grains__ .get ('os_family' ) == 'Gentoo' :
211
+ return __salt__ ['cmd.retcode' ](
212
+ 'locale-gen --generate "{0}"' .format (locale )
213
+ )
214
+ else :
215
+ return __salt__ ['cmd.retcode' ](
216
+ 'locale-gen "{0}"' .format (locale )
217
+ )
197
218
198
- return True
219
+ return False
0 commit comments