tldr-pages / tldr-python-client

Python command-line client for tldr pages
https://pypi.org/project/tldr/
MIT License
596 stars 93 forks source link

Feature Proposal: Custom default language #156

Closed nebnola closed 3 years ago

nebnola commented 3 years ago

Hi, I just discovered your project and think this would be a useful feature: A TLDR_LANGUAGE environment variable that sets the default language for tldr. This way, users who want tldr to use a different language by default than the system language can set it permanently in their ~/.bashrc. I would be happy to write the changes myself, I'd just like to know if that feature would be welcome or not.

MasterOdin commented 3 years ago

I have no qualms with adding this. I think it would follow the LANG specification (e.g. a singular 4 character language code to use) and that the language look-up would be to prepend TLDR_LANGUAGE environment variable to the language list look-up that is derived as part of the client specification.

Implementation would be (I think) to modify the get_language_list function to do this check and prepend and also get_default_langauge function so that it gets returned instead LANG if set.

bl-ue commented 3 years ago

As a matter of fact, I don't believe this client is even complying with the spec until this is fixed.

If a client has access to environment variables, it MUST use them derive the preferred user language as described in the next paragraphs.

MasterOdin commented 3 years ago

@bl-ue The spec prescribes only usage of the LANG and LANGUAGE environment variables as being used to determine language, which this client does do and is spec compliant.

Adding support for TLDR_LANGUAGE would if anything make the client less spec compliant, but I think it's a useful feature, and one that can be used as an implementation reference to perhaps adopting into the spec (or at the very least add language to the spec allowing this modification).

bl-ue commented 3 years ago

Oh, I see. I thought that TLDR_LANGUAGE was merely a suggestion. @nebnola are you aware that you can set LANG=de (for example) to customize the default language that tldr uses?

nebnola commented 3 years ago

Yes, I'm aware of that. However LANG affects the whole system, while I would like to be able to set a default for tldr without specifying the -L argument each time. So basically, if -L is unset, as @MasterOdin said, I would prepend the value of TLDR_LANGUAGE to the existing list which is derived from LANGand LANGUAGES

MasterOdin commented 3 years ago

Hm, thinking about it, I think that you want to modify the get_language_list function to prepend the value of TLDR_LANGUAGE and modify here:

https://github.com/tldr-pages/tldr-python-client/blob/f24f81fb01d2b1bb69840bc6f98921fcbd700033/tldr.py#L340-L341

so that it first calls a function that returns the value of TLDR_LANGUAGE, and if that's not set, then it calls get_default_language, or something of that nature. We would ideally keep the behavior of appending LANG into LANGUAGES if both are set, but still allow the usage of TLDR_LANGUAGE as the principal language if set.

Hopefully that makes sense.

nebnola commented 3 years ago

Resolved by #157. Thanks everyone for your help!