15
15
16
16
import xmltodict
17
17
18
+ from flattentool .i18n import _
18
19
from flattentool .input import path_search
19
20
from flattentool .schema import make_sub_sheet_name
20
21
from flattentool .sheet import Sheet
@@ -146,7 +147,7 @@ def __init__(
146
147
if isinstance (rollup , (list ,)) and (
147
148
len (rollup ) > 1 or (len (rollup ) == 1 and rollup [0 ] is not True )
148
149
):
149
- warn ("Using rollUp values from schema, ignoring direct input." )
150
+ warn (_ ( "Using rollUp values from schema, ignoring direct input." ) )
150
151
elif isinstance (rollup , (list ,)):
151
152
if len (rollup ) == 1 and os .path .isfile (rollup [0 ]):
152
153
# Parse file, one json path per line.
@@ -159,13 +160,17 @@ def __init__(
159
160
# Rollup args passed directly at the commandline
160
161
elif len (rollup ) == 1 and rollup [0 ] is True :
161
162
warn (
162
- "No fields to rollup found (pass json path directly, as a list in a file, or via a schema)"
163
+ _ (
164
+ "No fields to rollup found (pass json path directly, as a list in a file, or via a schema)"
165
+ )
163
166
)
164
167
else :
165
168
self .rollup = set (rollup )
166
169
else :
167
170
warn (
168
- "Invalid value passed for rollup (pass json path directly, as a list in a file, or via a schema)"
171
+ _ (
172
+ "Invalid value passed for rollup (pass json path directly, as a list in a file, or via a schema)"
173
+ )
169
174
)
170
175
171
176
if self .xml :
@@ -180,11 +185,13 @@ def __init__(
180
185
json_filename = None
181
186
182
187
if json_filename is None and root_json_dict is None :
183
- raise ValueError ("Etiher json_filename or root_json_dict must be supplied" )
188
+ raise ValueError (
189
+ _ ("Etiher json_filename or root_json_dict must be supplied" )
190
+ )
184
191
185
192
if json_filename is not None and root_json_dict is not None :
186
193
raise ValueError (
187
- "Only one of json_file or root_json_dict should be supplied"
194
+ _ ( "Only one of json_file or root_json_dict should be supplied" )
188
195
)
189
196
190
197
if json_filename :
@@ -222,9 +229,9 @@ def __init__(
222
229
if field not in self .schema_parser .flattened .keys ():
223
230
input_not_in_schema .add (field )
224
231
warn (
225
- "You wanted to preserve the following fields which are not present in the supplied schema: {}" . format (
226
- list ( input_not_in_schema )
227
- )
232
+ _ (
233
+ "You wanted to preserve the following fields which are not present in the supplied schema: {}"
234
+ ). format ( list ( input_not_in_schema ))
228
235
)
229
236
except AttributeError :
230
237
# no schema
@@ -260,9 +267,9 @@ def parse(self):
260
267
nonexistent_input_paths .append (field )
261
268
if len (nonexistent_input_paths ) > 0 :
262
269
warn (
263
- "You wanted to preserve the following fields which are not present in the input data: {}" . format (
264
- nonexistent_input_paths
265
- )
270
+ _ (
271
+ "You wanted to preserve the following fields which are not present in the input data: {}"
272
+ ). format ( nonexistent_input_paths )
266
273
)
267
274
268
275
def parse_json_dict (
@@ -366,7 +373,9 @@ def parse_json_dict(
366
373
367
374
if self .use_titles and not self .schema_parser :
368
375
warn (
369
- "Warning: No schema was provided so column headings are JSON keys, not titles."
376
+ _ (
377
+ "Warning: No schema was provided so column headings are JSON keys, not titles."
378
+ )
370
379
)
371
380
372
381
if len (value ) == 1 :
@@ -381,7 +390,7 @@ def parse_json_dict(
381
390
382
391
if type (v ) not in BASIC_TYPES :
383
392
raise ValueError (
384
- "Rolled up values must be basic types"
393
+ _ ( "Rolled up values must be basic types" )
385
394
)
386
395
else :
387
396
if self .schema_parser :
@@ -458,22 +467,26 @@ def parse_json_dict(
458
467
in self .schema_parser .main_sheet
459
468
):
460
469
warn (
461
- 'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.' . format (
462
- parent_name + key
463
- )
470
+ _ (
471
+ 'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.'
472
+ ). format ( parent_name + key )
464
473
)
465
474
flattened_dict [
466
475
sheet_key (sheet , parent_name + key + "/0/" + k )
467
- ] = "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
476
+ ] = _ (
477
+ "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
478
+ )
468
479
elif parent_name + key in self .rollup :
469
480
warn (
470
- 'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.' . format (
471
- parent_name + key
472
- )
481
+ _ (
482
+ 'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.'
483
+ ). format ( parent_name + key )
473
484
)
474
485
flattened_dict [
475
486
sheet_key (sheet , parent_name + key + "/0/" + k )
476
- ] = "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
487
+ ] = _ (
488
+ "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
489
+ )
477
490
478
491
if (
479
492
self .use_titles
@@ -502,7 +515,7 @@ def parse_json_dict(
502
515
top_level_of_sub_sheet = True ,
503
516
)
504
517
else :
505
- raise ValueError ("Unsupported type {}" .format (type (value )))
518
+ raise ValueError (_ ( "Unsupported type {}" ) .format (type (value )))
506
519
507
520
if top :
508
521
sheet .lines .append (flattened_dict )
0 commit comments