| 1 |
import json |
| 2 |
import os |
| 3 |
import shutil |
| 4 |
|
| 5 |
import regex as re |
| 6 |
|
| 7 |
from dateparser_scripts.order_languages import _get_language_locale_dict |
| 8 |
from dateparser_scripts.utils import get_dict_difference, get_raw_data, CLDR_JSON_DIR |
| 9 |
|
| 10 |
APOSTROPHE_LOOK_ALIKE_CHARS = [ |
| 11 |
"\N{RIGHT SINGLE QUOTATION MARK}", # '\u2019' |
| 12 |
"\N{MODIFIER LETTER APOSTROPHE}", # '\u02bc' |
| 13 |
"\N{MODIFIER LETTER TURNED COMMA}", # '\u02bb' |
| 14 |
"\N{ARMENIAN APOSTROPHE}", # '\u055a' |
| 15 |
"\N{LATIN SMALL LETTER SALTILLO}", # '\ua78c' |
| 16 |
"\N{PRIME}", # '\u2032' |
| 17 |
"\N{REVERSED PRIME}", # '\u2035' |
| 18 |
"\N{MODIFIER LETTER PRIME}", # '\u02b9' |
| 19 |
"\N{FULLWIDTH APOSTROPHE}", # '\uff07' |
| 20 |
] |
| 21 |
|
| 22 |
DATE_ORDER_PATTERN = re.compile( |
| 23 |
"([DMY])+\u200f*[-/. \t]*([DMY])+\u200f*[-/. \t]*([DMY])+" |
| 24 |
) |
| 25 |
RELATIVE_PATTERN = re.compile(r"(?<![\+\-]\s*)\{0\}") |
| 26 |
DEFAULT_MONTH_PATTERN = re.compile(r"^M?\d+$", re.U) |
| 27 |
RE_SANITIZE_APOSTROPHE = re.compile("|".join(APOSTROPHE_LOOK_ALIKE_CHARS)) |
| 28 |
AM_PATTERN = re.compile(r"^\s*[Aa]\s*\.?\s*[Mm]\s*\.?\s*$") |
| 29 |
PM_PATTERN = re.compile(r"^\s*[Pp]\s*\.?\s*[Mm]\s*\.?\s*$") |
| 30 |
PARENTHESIS_PATTERN = re.compile(r"[\(\)]") |
| 31 |
|
| 32 |
|
| 33 |
def _filter_relative_string(relative_string): |
| 34 |
return ( |
| 35 |
isinstance(relative_string, str) |
| 36 |
and RELATIVE_PATTERN.search(relative_string) |
| 37 |
and not PARENTHESIS_PATTERN.search(relative_string) |
| 38 |
) |
| 39 |
|
| 40 |
|
| 41 |
def _filter_month_name(month_name): |
| 42 |
return not DEFAULT_MONTH_PATTERN.match(month_name) |
| 43 |
|
| 44 |
|
| 45 |
def _retrieve_locale_data(locale): |
| 46 |
def load(scope, file_id): |
| 47 |
file_path = ( |
| 48 |
CLDR_JSON_DIR |
| 49 |
/ "cldr-json" |
| 50 |
/ f"cldr-{scope}-full" |
| 51 |
/ "main" |
| 52 |
/ locale |
| 53 |
/ f"{file_id}.json" |
| 54 |
) |
| 55 |
with file_path.open() as f: |
| 56 |
return json.load(f) |
| 57 |
|
| 58 |
cldr_gregorian_data = load("dates", "ca-gregorian") |
| 59 |
cldr_datefields_data = load("dates", "dateFields") |
| 60 |
_units = load("units", "units") |
| 61 |
|
| 62 |
gregorian_dict = cldr_gregorian_data["main"][locale]["dates"]["calendars"][ |
| 63 |
"gregorian" |
| 64 |
] |
| 65 |
date_fields_dict = cldr_datefields_data["main"][locale]["dates"]["fields"] |
| 66 |
units = _units["main"][locale]["units"]["long"] |
| 67 |
|
| 68 |
json_dict = {} |
| 69 |
|
| 70 |
field_keys_1 = ["stand-alone", "format"] |
| 71 |
field_keys_2 = [ |
| 72 |
"wide", |
| 73 |
"abbreviated", |
| 74 |
] # neglecting "narrow" to avoid problems in translation |
| 75 |
year_keys = ["year", "year-short", "year-narrow"] |
| 76 |
month_keys = ["month", "month-short", "month-narrow"] |
| 77 |
week_keys = ["week", "week-short", "week-narrow"] |
| 78 |
day_keys = ["day", "day-short", "day-narrow"] |
| 79 |
hour_keys = ["hour", "hour-short", "hour-narrow"] |
| 80 |
minute_keys = ["minute", "minute-short", "minute-narrow"] |
| 81 |
second_keys = ["second", "second-short", "second-narrow"] |
| 82 |
relative_keys = ["relativeTimePattern-count-one", "relativeTimePattern-count-other"] |
| 83 |
|
| 84 |
json_dict["name"] = locale |
| 85 |
|
| 86 |
try: |
| 87 |
date_format_string = gregorian_dict["dateFormats"]["short"].upper() |
| 88 |
except AttributeError: |
| 89 |
date_format_string = gregorian_dict["dateFormats"]["short"]["_value"].upper() |
| 90 |
|
| 91 |
json_dict["date_order"] = DATE_ORDER_PATTERN.sub( |
| 92 |
r"\1\2\3", DATE_ORDER_PATTERN.search(date_format_string).group() |
| 93 |
) |
| 94 |
|
| 95 |
json_dict["january"] = list( |
| 96 |
filter( |
| 97 |
_filter_month_name, |
| 98 |
[ |
| 99 |
gregorian_dict["months"][key1][key2]["1"] |
| 100 |
for key1 in field_keys_1 |
| 101 |
for key2 in field_keys_2 |
| 102 |
], |
| 103 |
) |
| 104 |
) |
| 105 |
|
| 106 |
json_dict["february"] = list( |
| 107 |
filter( |
| 108 |
_filter_month_name, |
| 109 |
[ |
| 110 |
gregorian_dict["months"][key1][key2]["2"] |
| 111 |
for key1 in field_keys_1 |
| 112 |
for key2 in field_keys_2 |
| 113 |
], |
| 114 |
) |
| 115 |
) |
| 116 |
|
| 117 |
json_dict["march"] = list( |
| 118 |
filter( |
| 119 |
_filter_month_name, |
| 120 |
[ |
| 121 |
gregorian_dict["months"][key1][key2]["3"] |
| 122 |
for key1 in field_keys_1 |
| 123 |
for key2 in field_keys_2 |
| 124 |
], |
| 125 |
) |
| 126 |
) |
| 127 |
|
| 128 |
json_dict["april"] = list( |
| 129 |
filter( |
| 130 |
_filter_month_name, |
| 131 |
[ |
| 132 |
gregorian_dict["months"][key1][key2]["4"] |
| 133 |
for key1 in field_keys_1 |
| 134 |
for key2 in field_keys_2 |
| 135 |
], |
| 136 |
) |
| 137 |
) |
| 138 |
|
| 139 |
json_dict["may"] = list( |
| 140 |
filter( |
| 141 |
_filter_month_name, |
| 142 |
[ |
| 143 |
gregorian_dict["months"][key1][key2]["5"] |
| 144 |
for key1 in field_keys_1 |
| 145 |
for key2 in field_keys_2 |
| 146 |
], |
| 147 |
) |
| 148 |
) |
| 149 |
|
| 150 |
json_dict["june"] = list( |
| 151 |
filter( |
| 152 |
_filter_month_name, |
| 153 |
[ |
| 154 |
gregorian_dict["months"][key1][key2]["6"] |
| 155 |
for key1 in field_keys_1 |
| 156 |
for key2 in field_keys_2 |
| 157 |
], |
| 158 |
) |
| 159 |
) |
| 160 |
|
| 161 |
json_dict["july"] = list( |
| 162 |
filter( |
| 163 |
_filter_month_name, |
| 164 |
[ |
| 165 |
gregorian_dict["months"][key1][key2]["7"] |
| 166 |
for key1 in field_keys_1 |
| 167 |
for key2 in field_keys_2 |
| 168 |
], |
| 169 |
) |
| 170 |
) |
| 171 |
|
| 172 |
json_dict["august"] = list( |
| 173 |
filter( |
| 174 |
_filter_month_name, |
| 175 |
[ |
| 176 |
gregorian_dict["months"][key1][key2]["8"] |
| 177 |
for key1 in field_keys_1 |
| 178 |
for key2 in field_keys_2 |
| 179 |
], |
| 180 |
) |
| 181 |
) |
| 182 |
|
| 183 |
json_dict["september"] = list( |
| 184 |
filter( |
| 185 |
_filter_month_name, |
| 186 |
[ |
| 187 |
gregorian_dict["months"][key1][key2]["9"] |
| 188 |
for key1 in field_keys_1 |
| 189 |
for key2 in field_keys_2 |
| 190 |
], |
| 191 |
) |
| 192 |
) |
| 193 |
|
| 194 |
json_dict["october"] = list( |
| 195 |
filter( |
| 196 |
_filter_month_name, |
| 197 |
[ |
| 198 |
gregorian_dict["months"][key1][key2]["10"] |
| 199 |
for key1 in field_keys_1 |
| 200 |
for key2 in field_keys_2 |
| 201 |
], |
| 202 |
) |
| 203 |
) |
| 204 |
|
| 205 |
json_dict["november"] = list( |
| 206 |
filter( |
| 207 |
_filter_month_name, |
| 208 |
[ |
| 209 |
gregorian_dict["months"][key1][key2]["11"] |
| 210 |
for key1 in field_keys_1 |
| 211 |
for key2 in field_keys_2 |
| 212 |
], |
| 213 |
) |
| 214 |
) |
| 215 |
|
| 216 |
json_dict["december"] = list( |
| 217 |
filter( |
| 218 |
_filter_month_name, |
| 219 |
[ |
| 220 |
gregorian_dict["months"][key1][key2]["12"] |
| 221 |
for key1 in field_keys_1 |
| 222 |
for key2 in field_keys_2 |
| 223 |
], |
| 224 |
) |
| 225 |
) |
| 226 |
|
| 227 |
json_dict["monday"] = [ |
| 228 |
gregorian_dict["days"][key1][key2]["mon"] |
| 229 |
for key1 in field_keys_1 |
| 230 |
for key2 in field_keys_2 |
| 231 |
] |
| 232 |
|
| 233 |
json_dict["tuesday"] = [ |
| 234 |
gregorian_dict["days"][key1][key2]["tue"] |
| 235 |
for key1 in field_keys_1 |
| 236 |
for key2 in field_keys_2 |
| 237 |
] |
| 238 |
|
| 239 |
json_dict["wednesday"] = [ |
| 240 |
gregorian_dict["days"][key1][key2]["wed"] |
| 241 |
for key1 in field_keys_1 |
| 242 |
for key2 in field_keys_2 |
| 243 |
] |
| 244 |
|
| 245 |
json_dict["thursday"] = [ |
| 246 |
gregorian_dict["days"][key1][key2]["thu"] |
| 247 |
for key1 in field_keys_1 |
| 248 |
for key2 in field_keys_2 |
| 249 |
] |
| 250 |
|
| 251 |
json_dict["friday"] = [ |
| 252 |
gregorian_dict["days"][key1][key2]["fri"] |
| 253 |
for key1 in field_keys_1 |
| 254 |
for key2 in field_keys_2 |
| 255 |
] |
| 256 |
|
| 257 |
json_dict["saturday"] = [ |
| 258 |
gregorian_dict["days"][key1][key2]["sat"] |
| 259 |
for key1 in field_keys_1 |
| 260 |
for key2 in field_keys_2 |
| 261 |
] |
| 262 |
|
| 263 |
json_dict["sunday"] = [ |
| 264 |
gregorian_dict["days"][key1][key2]["sun"] |
| 265 |
for key1 in field_keys_1 |
| 266 |
for key2 in field_keys_2 |
| 267 |
] |
| 268 |
|
| 269 |
json_dict["am"] = [ |
| 270 |
AM_PATTERN.sub("am", x) |
| 271 |
for x in [ |
| 272 |
gregorian_dict["dayPeriods"][key1][key2]["am"] |
| 273 |
for key1 in field_keys_1 |
| 274 |
for key2 in field_keys_2 |
| 275 |
] |
| 276 |
] |
| 277 |
|
| 278 |
json_dict["pm"] = [ |
| 279 |
PM_PATTERN.sub("pm", x) |
| 280 |
for x in [ |
| 281 |
gregorian_dict["dayPeriods"][key1][key2]["pm"] |
| 282 |
for key1 in field_keys_1 |
| 283 |
for key2 in field_keys_2 |
| 284 |
] |
| 285 |
] |
| 286 |
|
| 287 |
json_dict["year"] = [date_fields_dict[key]["displayName"] for key in year_keys] |
| 288 |
|
| 289 |
json_dict["month"] = [date_fields_dict[key]["displayName"] for key in month_keys] |
| 290 |
|
| 291 |
json_dict["week"] = [date_fields_dict[key]["displayName"] for key in week_keys] |
| 292 |
|
| 293 |
json_dict["day"] = [date_fields_dict[key]["displayName"] for key in day_keys] |
| 294 |
|
| 295 |
json_dict["hour"] = [date_fields_dict[key]["displayName"] for key in hour_keys] |
| 296 |
hour_unit = units["duration-hour"]["displayName"] |
| 297 |
if hour_unit not in json_dict["hour"]: |
| 298 |
json_dict["hour"].append(hour_unit) |
| 299 |
|
| 300 |
json_dict["minute"] = [date_fields_dict[key]["displayName"] for key in minute_keys] |
| 301 |
|
| 302 |
json_dict["second"] = [date_fields_dict[key]["displayName"] for key in second_keys] |
| 303 |
|
| 304 |
json_dict["relative-type"] = {} |
| 305 |
|
| 306 |
json_dict["relative-type"]["1 year ago"] = [ |
| 307 |
date_fields_dict[key]["relative-type--1"] for key in year_keys |
| 308 |
] |
| 309 |
|
| 310 |
json_dict["relative-type"]["0 year ago"] = [ |
| 311 |
date_fields_dict[key]["relative-type-0"] for key in year_keys |
| 312 |
] |
| 313 |
|
| 314 |
json_dict["relative-type"]["in 1 year"] = [ |
| 315 |
date_fields_dict[key]["relative-type-1"] for key in year_keys |
| 316 |
] |
| 317 |
|
| 318 |
json_dict["relative-type"]["1 month ago"] = [ |
| 319 |
date_fields_dict[key]["relative-type--1"] for key in month_keys |
| 320 |
] |
| 321 |
|
| 322 |
json_dict["relative-type"]["0 month ago"] = [ |
| 323 |
date_fields_dict[key]["relative-type-0"] for key in month_keys |
| 324 |
] |
| 325 |
|
| 326 |
json_dict["relative-type"]["in 1 month"] = [ |
| 327 |
date_fields_dict[key]["relative-type-1"] for key in month_keys |
| 328 |
] |
| 329 |
|
| 330 |
json_dict["relative-type"]["1 week ago"] = [ |
| 331 |
date_fields_dict[key]["relative-type--1"] for key in week_keys |
| 332 |
] |
| 333 |
|
| 334 |
json_dict["relative-type"]["0 week ago"] = [ |
| 335 |
date_fields_dict[key]["relative-type-0"] for key in week_keys |
| 336 |
] |
| 337 |
|
| 338 |
json_dict["relative-type"]["in 1 week"] = [ |
| 339 |
date_fields_dict[key]["relative-type-1"] for key in week_keys |
| 340 |
] |
| 341 |
|
| 342 |
json_dict["relative-type"]["1 day ago"] = [ |
| 343 |
date_fields_dict[key]["relative-type--1"] for key in day_keys |
| 344 |
] |
| 345 |
|
| 346 |
json_dict["relative-type"]["0 day ago"] = [ |
| 347 |
date_fields_dict[key]["relative-type-0"] for key in day_keys |
| 348 |
] |
| 349 |
|
| 350 |
json_dict["relative-type"]["in 1 day"] = [ |
| 351 |
date_fields_dict[key]["relative-type-1"] for key in day_keys |
| 352 |
] |
| 353 |
|
| 354 |
json_dict["relative-type"]["0 hour ago"] = [ |
| 355 |
date_fields_dict[key]["relative-type-0"] for key in hour_keys |
| 356 |
] |
| 357 |
|
| 358 |
json_dict["relative-type"]["0 minute ago"] = [ |
| 359 |
date_fields_dict[key]["relative-type-0"] for key in minute_keys |
| 360 |
] |
| 361 |
|
| 362 |
json_dict["relative-type"]["0 second ago"] = [ |
| 363 |
date_fields_dict[key]["relative-type-0"] for key in second_keys |
| 364 |
] |
| 365 |
|
| 366 |
json_dict["relative-type-regex"] = {} |
| 367 |
|
| 368 |
json_dict["relative-type-regex"]["in \\1 year"] = list( |
| 369 |
filter( |
| 370 |
_filter_relative_string, |
| 371 |
[ |
| 372 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 373 |
for key1 in year_keys |
| 374 |
for key2 in relative_keys |
| 375 |
], |
| 376 |
) |
| 377 |
) |
| 378 |
|
| 379 |
json_dict["relative-type-regex"]["\\1 year ago"] = list( |
| 380 |
filter( |
| 381 |
_filter_relative_string, |
| 382 |
[ |
| 383 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 384 |
for key1 in year_keys |
| 385 |
for key2 in relative_keys |
| 386 |
], |
| 387 |
) |
| 388 |
) |
| 389 |
|
| 390 |
json_dict["relative-type-regex"]["in \\1 month"] = list( |
| 391 |
filter( |
| 392 |
_filter_relative_string, |
| 393 |
[ |
| 394 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 395 |
for key1 in month_keys |
| 396 |
for key2 in relative_keys |
| 397 |
], |
| 398 |
) |
| 399 |
) |
| 400 |
|
| 401 |
json_dict["relative-type-regex"]["\\1 month ago"] = list( |
| 402 |
filter( |
| 403 |
_filter_relative_string, |
| 404 |
[ |
| 405 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 406 |
for key1 in month_keys |
| 407 |
for key2 in relative_keys |
| 408 |
], |
| 409 |
) |
| 410 |
) |
| 411 |
|
| 412 |
json_dict["relative-type-regex"]["in \\1 week"] = list( |
| 413 |
filter( |
| 414 |
_filter_relative_string, |
| 415 |
[ |
| 416 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 417 |
for key1 in week_keys |
| 418 |
for key2 in relative_keys |
| 419 |
], |
| 420 |
) |
| 421 |
) |
| 422 |
|
| 423 |
json_dict["relative-type-regex"]["\\1 week ago"] = list( |
| 424 |
filter( |
| 425 |
_filter_relative_string, |
| 426 |
[ |
| 427 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 428 |
for key1 in week_keys |
| 429 |
for key2 in relative_keys |
| 430 |
], |
| 431 |
) |
| 432 |
) |
| 433 |
|
| 434 |
json_dict["relative-type-regex"]["in \\1 day"] = list( |
| 435 |
filter( |
| 436 |
_filter_relative_string, |
| 437 |
[ |
| 438 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 439 |
for key1 in day_keys |
| 440 |
for key2 in relative_keys |
| 441 |
], |
| 442 |
) |
| 443 |
) |
| 444 |
|
| 445 |
json_dict["relative-type-regex"]["\\1 day ago"] = list( |
| 446 |
filter( |
| 447 |
_filter_relative_string, |
| 448 |
[ |
| 449 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 450 |
for key1 in day_keys |
| 451 |
for key2 in relative_keys |
| 452 |
], |
| 453 |
) |
| 454 |
) |
| 455 |
|
| 456 |
json_dict["relative-type-regex"]["in \\1 hour"] = list( |
| 457 |
filter( |
| 458 |
_filter_relative_string, |
| 459 |
[ |
| 460 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 461 |
for key1 in hour_keys |
| 462 |
for key2 in relative_keys |
| 463 |
], |
| 464 |
) |
| 465 |
) |
| 466 |
|
| 467 |
json_dict["relative-type-regex"]["\\1 hour ago"] = list( |
| 468 |
filter( |
| 469 |
_filter_relative_string, |
| 470 |
[ |
| 471 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 472 |
for key1 in hour_keys |
| 473 |
for key2 in relative_keys |
| 474 |
], |
| 475 |
) |
| 476 |
) |
| 477 |
|
| 478 |
json_dict["relative-type-regex"]["in \\1 minute"] = list( |
| 479 |
filter( |
| 480 |
_filter_relative_string, |
| 481 |
[ |
| 482 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 483 |
for key1 in minute_keys |
| 484 |
for key2 in relative_keys |
| 485 |
], |
| 486 |
) |
| 487 |
) |
| 488 |
|
| 489 |
json_dict["relative-type-regex"]["\\1 minute ago"] = list( |
| 490 |
filter( |
| 491 |
_filter_relative_string, |
| 492 |
[ |
| 493 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 494 |
for key1 in minute_keys |
| 495 |
for key2 in relative_keys |
| 496 |
], |
| 497 |
) |
| 498 |
) |
| 499 |
|
| 500 |
json_dict["relative-type-regex"]["in \\1 second"] = list( |
| 501 |
filter( |
| 502 |
_filter_relative_string, |
| 503 |
[ |
| 504 |
date_fields_dict[key1]["relativeTime-type-future"].get(key2) |
| 505 |
for key1 in second_keys |
| 506 |
for key2 in relative_keys |
| 507 |
], |
| 508 |
) |
| 509 |
) |
| 510 |
|
| 511 |
json_dict["relative-type-regex"]["\\1 second ago"] = list( |
| 512 |
filter( |
| 513 |
_filter_relative_string, |
| 514 |
[ |
| 515 |
date_fields_dict[key1]["relativeTime-type-past"].get(key2) |
| 516 |
for key1 in second_keys |
| 517 |
for key2 in relative_keys |
| 518 |
], |
| 519 |
) |
| 520 |
) |
| 521 |
|
| 522 |
return json_dict |
| 523 |
|
| 524 |
|
| 525 |
def _clean_string(given_string): |
| 526 |
given_string = RE_SANITIZE_APOSTROPHE.sub("'", given_string) |
| 527 |
given_string = given_string.replace(".", "") |
| 528 |
given_string = given_string.lower() |
| 529 |
return " ".join(given_string.split()) |
| 530 |
|
| 531 |
|
| 532 |
def _clean_dict(json_dict): |
| 533 |
"""Remove duplicates and sort""" |
| 534 |
for key, value in json_dict.items(): |
| 535 |
if isinstance(value, list): |
| 536 |
json_dict[key] = sorted(dict.fromkeys(map(_clean_string, value))) |
| 537 |
elif isinstance(value, dict): |
| 538 |
json_dict[key] = dict(sorted(value.items())) |
| 539 |
json_dict[key] = _clean_dict(json_dict[key]) |
| 540 |
return dict(filter(lambda x: x[1], json_dict.items())) |
| 541 |
|
| 542 |
|
| 543 |
def main(): |
| 544 |
get_raw_data() |
| 545 |
language_locale_dict = _get_language_locale_dict() |
| 546 |
parent_directory = "../dateparser_data/cldr_language_data" |
| 547 |
directory = "../dateparser_data/cldr_language_data/date_translation_data/" |
| 548 |
if not os.path.isdir(parent_directory): |
| 549 |
os.mkdir(parent_directory) |
| 550 |
if os.path.isdir(directory): |
| 551 |
shutil.rmtree(directory) |
| 552 |
os.mkdir(directory) |
| 553 |
|
| 554 |
for language in language_locale_dict: |
| 555 |
json_language_dict = _clean_dict(_retrieve_locale_data(language)) |
| 556 |
locale_specific_dict = {} |
| 557 |
locales_list = language_locale_dict[language] |
| 558 |
for locale in locales_list: |
| 559 |
json_locale_dict = _clean_dict(_retrieve_locale_data(locale)) |
| 560 |
locale_specific_dict[locale] = _clean_dict( |
| 561 |
get_dict_difference(json_language_dict, json_locale_dict) |
| 562 |
) |
| 563 |
json_language_dict["locale_specific"] = dict( |
| 564 |
sorted(locale_specific_dict.items()) |
| 565 |
) |
| 566 |
filename = directory + language + ".json" |
| 567 |
print("writing " + filename) |
| 568 |
json_string = json.dumps( |
| 569 |
json_language_dict, indent=4, separators=(",", ": "), ensure_ascii=False |
| 570 |
).encode("utf-8") |
| 571 |
with open(filename, "wb") as f: |
| 572 |
f.write(json_string) |
| 573 |
|
| 574 |
|
| 575 |
if __name__ == "__main__": |
| 576 |
main() |