Skip to content

Commit 2891458

Browse files
committed
Respect language settings when geting a list of commands
Fixes: #238
1 parent 68acf05 commit 2891458

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tldr.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,24 @@ def get_page(
305305
PARAM_REGEX = re.compile(r'(?:{{)(?P<param>.+?)(?:}})')
306306

307307

308-
def get_commands(platforms: Optional[List[str]] = None) -> List[str]:
308+
def get_commands(platforms: Optional[List[str]] = None, language: Optional[str] = None) -> List[str]:
309309
if platforms is None:
310310
platforms = get_platform_list()
311311

312+
if language:
313+
languages = [get_language_code(language[0])]
314+
else:
315+
languages = get_language_list()
316+
312317
commands = []
313318
if get_cache_dir().exists():
314319
for platform in platforms:
315-
path = get_cache_dir() / 'pages' / platform
316-
if not path.exists():
317-
continue
318-
commands += [file.stem for file in path.iterdir() if file.suffix == '.md']
320+
for language in languages:
321+
pages_dir = f'pages.{language}' if language != 'en' else 'pages'
322+
path = get_cache_dir() / pages_dir / platform
323+
if not path.exists():
324+
continue
325+
commands += [file.stem for file in path.iterdir() if file.suffix == '.md']
319326
return commands
320327

321328

@@ -511,7 +518,7 @@ def main() -> None:
511518
parser.print_help(sys.stderr)
512519
sys.exit(1)
513520
if options.list:
514-
print('\n'.join(get_commands(options.platform)))
521+
print('\n'.join(get_commands(options.platform, options.language)))
515522
elif options.render:
516523
for command in options.command:
517524
if Path(command).exists():

0 commit comments

Comments
 (0)