55import os
66
77# local imports
8- import scripts ._locale as locale
8+ import scripts .localize as localize
99
1010
1111def parse_args (* args ):
@@ -22,7 +22,7 @@ def parse_args(*args):
2222 Parsed arguments.
2323 """
2424
25- return locale .build_arg_parser ().parse_args (args )
25+ return localize .build_arg_parser ().parse_args (args )
2626
2727
2828def test_build_context_uses_github_defaults (monkeypatch , tmp_path ):
@@ -34,18 +34,18 @@ def test_build_context_uses_github_defaults(monkeypatch, tmp_path):
3434 monkeypatch .setenv ('GITHUB_SERVER_URL' , 'https://github.example' )
3535 monkeypatch .setenv ('GITHUB_REF_NAME' , 'master' )
3636
37- context = locale .build_context (args = parse_args ())
37+ context = localize .build_context (args = parse_args ())
3838
3939 assert context .root_dir == str (tmp_path )
4040 assert context .locale_dir == os .path .join (str (tmp_path ), 'locale' )
4141 assert context .source_directories == ['src' ]
42- assert context .extensions == locale .DEFAULT_EXTENSIONS
43- assert context .keywords == locale .DEFAULT_KEYWORDS
42+ assert context .extensions == localize .DEFAULT_EXTENSIONS
43+ assert context .keywords == localize .DEFAULT_KEYWORDS
4444 assert context .project_name == 'Example-Repo'
4545 assert context .project_owner == 'LizardByte'
4646 assert context .domain == 'example-repo'
4747 assert context .bugs_address == 'https://github.example/LizardByte/Example-Repo'
48- assert context .language_source_url == locale .LANGUAGES_URL
48+ assert context .language_source_url == localize .LANGUAGES_URL
4949 assert context .target_locales == []
5050
5151
@@ -85,7 +85,7 @@ def test_build_context_allows_cli_overrides(monkeypatch, tmp_path):
8585 'https://example.invalid/languages.json' ,
8686 )
8787
88- context = locale .build_context (args = args )
88+ context = localize .build_context (args = args )
8989
9090 assert context .root_dir == str (tmp_path )
9191 assert context .locale_dir == os .path .join (str (tmp_path ), 'i18n' )
@@ -196,7 +196,7 @@ def test_parse_target_locales_normalizes_i18n_metadata():
196196 },
197197 }
198198
199- assert locale .parse_target_locales (language_data = language_data ) == [
199+ assert localize .parse_target_locales (language_data = language_data ) == [
200200 'bg' ,
201201 'cs' ,
202202 'de' ,
@@ -242,7 +242,7 @@ def test_parse_target_locales_handles_missing_optional_metadata():
242242 },
243243 }
244244
245- assert locale .parse_target_locales (language_data = language_data ) == [
245+ assert localize .parse_target_locales (language_data = language_data ) == [
246246 'aa' ,
247247 'aa_AA' ,
248248 'aa_BB' ,
@@ -293,9 +293,9 @@ def fake_urlopen(url, timeout):
293293 assert timeout == 30
294294 return FakeResponse ()
295295
296- monkeypatch .setattr (locale .urllib .request , 'urlopen' , fake_urlopen )
296+ monkeypatch .setattr (localize .urllib .request , 'urlopen' , fake_urlopen )
297297
298- assert locale .load_target_locales (
298+ assert localize .load_target_locales (
299299 language_source_url = 'https://example.invalid/languages.json' ,
300300 ) == ['pt' , 'pt_BR' ]
301301
@@ -308,10 +308,10 @@ def fake_urlopen(url, timeout):
308308
309309 raise OSError ('offline' )
310310
311- monkeypatch .setattr (locale .urllib .request , 'urlopen' , fake_urlopen )
311+ monkeypatch .setattr (localize .urllib .request , 'urlopen' , fake_urlopen )
312312
313313 try :
314- locale .load_target_locales (language_source_url = 'https://example.invalid/languages.json' )
314+ localize .load_target_locales (language_source_url = 'https://example.invalid/languages.json' )
315315 except OSError as err :
316316 assert str (err ) == 'offline'
317317 else :
@@ -321,8 +321,8 @@ def fake_urlopen(url, timeout):
321321def test_resolve_path_handles_absolute_and_relative_paths (tmp_path ):
322322 """Verify path resolution handles absolute and relative paths."""
323323
324- assert locale .resolve_path (root_dir = str (tmp_path ), path = 'locale' ) == os .path .join (str (tmp_path ), 'locale' )
325- assert locale .resolve_path (root_dir = 'ignored' , path = str (tmp_path )) == str (tmp_path )
324+ assert localize .resolve_path (root_dir = str (tmp_path ), path = 'locale' ) == os .path .join (str (tmp_path ), 'locale' )
325+ assert localize .resolve_path (root_dir = 'ignored' , path = str (tmp_path )) == str (tmp_path )
326326
327327
328328def test_discover_locale_codes_returns_sorted_directories (tmp_path ):
@@ -333,8 +333,8 @@ def test_discover_locale_codes_returns_sorted_directories(tmp_path):
333333 with open (os .path .join (str (tmp_path ), 'README.md' ), mode = 'w' , encoding = 'utf-8' ) as file :
334334 file .write ('not a locale directory' )
335335
336- assert locale .discover_locale_codes (locale_dir = str (tmp_path )) == ['en' , 'fr' ]
337- assert locale .discover_locale_codes (locale_dir = os .path .join (str (tmp_path ), 'missing' )) == []
336+ assert localize .discover_locale_codes (locale_dir = str (tmp_path )) == ['en' , 'fr' ]
337+ assert localize .discover_locale_codes (locale_dir = os .path .join (str (tmp_path ), 'missing' )) == []
338338
339339
340340def test_collect_source_files_scans_existing_source_directories (tmp_path ):
@@ -352,7 +352,7 @@ def test_collect_source_files_scans_existing_source_directories(tmp_path):
352352 with open (file , mode = 'w' , encoding = 'utf-8' ) as file_handle :
353353 file_handle .write ('// test\n ' )
354354
355- assert locale .collect_source_files (
355+ assert localize .collect_source_files (
356356 root_dir = root_dir ,
357357 source_directories = ['src' , 'missing' ],
358358 extensions = ['cpp' , '.hpp' ],
@@ -376,7 +376,7 @@ def test_x_extract_builds_command_and_rewrites_header(monkeypatch, tmp_path):
376376 with open (os .path .join (root_dir , 'src' , 'nested' , 'helper.hpp' ), mode = 'w' , encoding = 'utf-8' ) as file :
377377 file .write ('gettext("World")\n ' )
378378
379- context = locale .build_context (args = parse_args ('--root-dir' , root_dir , '--project-name' , 'Example' ))
379+ context = localize .build_context (args = parse_args ('--root-dir' , root_dir , '--project-name' , 'Example' ))
380380 calls = []
381381
382382 def fake_check_output (args , cwd ):
@@ -392,16 +392,16 @@ def fake_check_output(args, cwd):
392392 file .write ('"Language: \\ n"\n ' )
393393 file .write ('msgid ""\n ' )
394394
395- monkeypatch .setattr (locale .subprocess , 'check_output' , fake_check_output )
395+ monkeypatch .setattr (localize .subprocess , 'check_output' , fake_check_output )
396396
397- locale .x_extract (context = context )
397+ localize .x_extract (context = context )
398398
399399 current_year = str (datetime .datetime .now ().year )
400400 assert calls == [
401401 {
402402 'args' : [
403403 'xgettext' ,
404- * [f'--keyword={ keyword } ' for keyword in locale .DEFAULT_KEYWORDS ],
404+ * [f'--keyword={ keyword } ' for keyword in localize .DEFAULT_KEYWORDS ],
405405 '--default-domain=example' ,
406406 f'--output={ os .path .join (context .locale_dir , "example.po" )} ' ,
407407 '--language=C++' ,
@@ -429,10 +429,10 @@ def fake_check_output(args, cwd):
429429def test_x_extract_requires_source_files (tmp_path ):
430430 """Verify extraction fails clearly when no source files are found."""
431431
432- context = locale .build_context (args = parse_args ('--root-dir' , str (tmp_path )))
432+ context = localize .build_context (args = parse_args ('--root-dir' , str (tmp_path )))
433433
434434 try :
435- locale .x_extract (context = context )
435+ localize .x_extract (context = context )
436436 except RuntimeError as err :
437437 assert str (err ) == 'No source files found for locale extraction.'
438438 else :
@@ -442,7 +442,7 @@ def test_x_extract_requires_source_files(tmp_path):
442442def test_babel_commands (monkeypatch , tmp_path ):
443443 """Verify pybabel commands use the resolved locale context."""
444444
445- context = locale .build_context (args = parse_args ('--root-dir' , str (tmp_path ), '--project-name' , 'Example' ))
445+ context = localize .build_context (args = parse_args ('--root-dir' , str (tmp_path ), '--project-name' , 'Example' ))
446446 calls = []
447447
448448 def fake_check_output (args , cwd ):
@@ -453,11 +453,11 @@ def fake_check_output(args, cwd):
453453 'cwd' : cwd ,
454454 })
455455
456- monkeypatch .setattr (locale .subprocess , 'check_output' , fake_check_output )
456+ monkeypatch .setattr (localize .subprocess , 'check_output' , fake_check_output )
457457
458- locale .babel_init (context = context , locale_code = 'fr' )
459- locale .babel_update (context = context )
460- locale .babel_compile (context = context )
458+ localize .babel_init (context = context , locale_code = 'fr' )
459+ localize .babel_update (context = context )
460+ localize .babel_compile (context = context )
461461
462462 assert calls == [
463463 {
@@ -506,7 +506,7 @@ def fake_check_output(args, cwd):
506506def test_init_missing_locales_only_initializes_missing_targets (monkeypatch , tmp_path ):
507507 """Verify locale initialization skips existing targets."""
508508
509- context = locale .build_context (args = parse_args ('--root-dir' , str (tmp_path ), '--locale' , 'en,fr' ))
509+ context = localize .build_context (args = parse_args ('--root-dir' , str (tmp_path ), '--locale' , 'en,fr' ))
510510 os .makedirs (os .path .join (context .locale_dir , 'en' ))
511511 initialized_locales = []
512512
@@ -515,34 +515,34 @@ def fake_babel_init(context, locale_code):
515515
516516 initialized_locales .append (locale_code )
517517
518- monkeypatch .setattr (locale , 'babel_init' , fake_babel_init )
518+ monkeypatch .setattr (localize , 'babel_init' , fake_babel_init )
519519
520- locale .init_missing_locales (context = context )
520+ localize .init_missing_locales (context = context )
521521
522522 assert initialized_locales == ['fr' ]
523523
524524
525525def test_init_missing_locales_loads_shared_targets (monkeypatch , tmp_path ):
526526 """Verify locale initialization loads shared targets when none are explicit."""
527527
528- context = locale .build_context (args = parse_args ('--root-dir' , str (tmp_path )))
528+ context = localize .build_context (args = parse_args ('--root-dir' , str (tmp_path )))
529529 os .makedirs (os .path .join (context .locale_dir , 'en' ))
530530 initialized_locales = []
531531
532532 def fake_load_target_locales (language_source_url ):
533533 """Return fake shared target locales."""
534534
535- assert language_source_url == locale .LANGUAGES_URL
535+ assert language_source_url == localize .LANGUAGES_URL
536536 return ['en' , 'vi' ]
537537
538538 def fake_babel_init (context , locale_code ):
539539 """Record initialized locale codes."""
540540
541541 initialized_locales .append (locale_code )
542542
543- monkeypatch .setattr (locale , 'load_target_locales' , fake_load_target_locales )
544- monkeypatch .setattr (locale , 'babel_init' , fake_babel_init )
543+ monkeypatch .setattr (localize , 'load_target_locales' , fake_load_target_locales )
544+ monkeypatch .setattr (localize , 'babel_init' , fake_babel_init )
545545
546- locale .init_missing_locales (context = context )
546+ localize .init_missing_locales (context = context )
547547
548548 assert initialized_locales == ['vi' ]
0 commit comments