Skip to content

Conversation

@lucasoshiro
Copy link
Contributor

Hi!

Although the https://github.com/tldr-pages/tldr repository has pages in other languages than English, the only way to read a page in another language was changing the page source with -s or --source.

This PR makes tldr detect the system language and use it to download the page in that language if it's available. Otherwise, it will download in English instead. It's also possible to provide the language with -l or --language.

@lucasoshiro lucasoshiro changed the title Language Add support for other languages Nov 11, 2019
@lucasoshiro
Copy link
Contributor Author

ping @waldyrious ! Can you review this, please? Thanks!

@ivanhercaz
Copy link

This PR is very interesting. When I have a bit of time I could review it, but I can't promise it, @lucasoshiro.

@lucasoshiro
Copy link
Contributor Author

@ivanhercaz ok, thanks!

@zlatanvasovic
Copy link
Contributor

@lucasoshiro I wasn't active much when you proposed this, so it seems I missed this PR.

This has some merge conflicts with the recently merged PRs that changed the way page requests operate. Are you still interested in working on this, to check if those recent changes work along with your proposed change?

Thank you for the valuable contribution nevertheless.

Add --language option, for getting page in another language. If the page
in the specified language is not available, download it in the default language.

Signed-off-by: Lucas Oshiro <[email protected]>
Detect the current system language, and use it as the default language
for downloading pages.

Signed-off-by: Lucas Oshiro <[email protected]>
@lucasoshiro
Copy link
Contributor Author

@zdroid I rebased this PR with master and solved the conflitcts, I think it's ok now. Thanks for the review!

@zlatanvasovic
Copy link
Contributor

zlatanvasovic commented Apr 30, 2020

What do you think about adding another TLDR_ configuration variable? Maybe TLDR_PAGES_LANGUAGE or just TLDR_LANGUAGE. It would replace the need to type -l <language> every time.

@MasterOdin
Copy link
Contributor

The client specification already includes words on how to support language environment variables: https://github.com/tldr-pages/tldr/blob/master/CLIENT-SPECIFICATION.md#language.

Copy link
Contributor

@MasterOdin MasterOdin left a comment

Choose a reason for hiding this comment

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

The load_page_from_cache and store_page_to_cache methods should be made language aware or else you'll have issues opening pages that exist in multiple languages when specifying the non-default language. For example, assume we have cd in fr and en and I default to fr. First usage will grab the fr page and store it to the cache as cd_common.md. Next time, I do --language en and it will display the cached fr page.

@zlatanvasovic
Copy link
Contributor

zlatanvasovic commented May 3, 2020

@MasterOdin I decided to merge #101 first because else we'd be making too many redundant changes. But we can move on to complete this one now.

I've resolved the merge conflicts. What's left is to fix the way update_cache() works, so that it doesn't store redundant languages.

@zlatanvasovic zlatanvasovic merged commit aa4546d into tldr-pages:master May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants