Skip to content

Add filter for languages with ll_CC description #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions tldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@
'https://tldr-pages.github.io/assets/tldr.zip'
)

DEFAULT_LANG = os.environ.get(
'LANG',
'C'
).split('_')[0]

def filter_languages(lang):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this name as it feels like what you might think it does from the name (given a list of languages, filter it down) is not the same as what it actually does (given a language, rewrite it to appropriate form). get_language_code(language) or get_tldr_language_code(language) maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, for me a filter is something which modifies or removes an input and outputs the result, but I see your point.

if lang in ['pt_PT', 'pt_BR', 'zh_TW']:
return lang
elif lang == "pt":
return "pt_PT"
return lang.split('_')[0]


DEFAULT_LANG = filter_languages(
os.environ.get(
'LANG',
'C'
).split('.')[0])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone know how to apply this filter with chain notation for a nicer syntax like
.split('.')[0].apply(filter_languages)?
Couldn't find a solution with a quick search.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the .split('.')[0] step into filter_languages as its first line, given we're doing a similar step below, and it would be good to condense it to one place, and would allow simplifying the double map below into a singular one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense.


if DEFAULT_LANG == 'C' or DEFAULT_LANG == 'POSIX':
DEFAULT_LANG = None
Expand Down Expand Up @@ -162,9 +172,11 @@ def get_platform_list():
def get_language_list():
languages = os.environ.get('LANGUAGE', '').split(':')
languages = list(map(
lambda x: x.split('_')[0],
filter(lambda x: not (x == 'C' or x == 'POSIX' or x == ''), languages)
))
filter_languages,
map(
lambda x: x.split('.')[0],
filter(lambda x: not (x == 'C' or x == 'POSIX' or x == ''), languages)
)))
if DEFAULT_LANG is not None:
if DEFAULT_LANG not in languages:
languages.append(DEFAULT_LANG)
Expand Down