From 2a856037a9b8bc08ab5e42eaf6f0943034bffcf7 Mon Sep 17 00:00:00 2001 From: columbarius Date: Tue, 16 Jun 2020 20:25:24 +0200 Subject: [PATCH 1/7] Change language priority --- tldr.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tldr.py b/tldr.py index bf65b13..234f989 100755 --- a/tldr.py +++ b/tldr.py @@ -27,9 +27,14 @@ 'https://tldr-pages.github.io/assets/tldr.zip' ) -DEFAULT_LANG = os.environ.get( +TLDR_LANG = os.environ.get( 'TLDR_LANGUAGE', - os.environ.get('LANG', None) + None +) + +DEFAULT_LANG = os.environ.get( + 'LANG', + 'C' ).split('_')[0] if DEFAULT_LANG == 'C': @@ -157,6 +162,8 @@ def get_platform_list(): def get_language_list(): + if TLDR_LANG is not None: + return [TLDR_LANG] languages = os.environ.get('LANGUAGES', '').split(':') languages = list(map( lambda x: x.split('_')[0], From 684a4b06d5fe945b86029fff02f1c8d62d496932 Mon Sep 17 00:00:00 2001 From: columbarius Date: Sat, 20 Jun 2020 23:42:10 +0200 Subject: [PATCH 2/7] Change language resolution to spec with english fallback --- tldr.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tldr.py b/tldr.py index 2805f54..01260e4 100755 --- a/tldr.py +++ b/tldr.py @@ -162,21 +162,24 @@ def get_platform_list(): def get_language_list(): - if TLDR_LANG is not None: - return [TLDR_LANG] languages = os.environ.get('LANGUAGE', '').split(':') languages = list(map( lambda x: x.split('_')[0], filter(lambda x: not (x == 'C' or x == ''), languages) )) if DEFAULT_LANG is not None: + if DEFAULT_LANG not in languages: + languages.append(DEFAULT_LANG) + else: + languages = [] + if TLDR_LANG is not None: try: - languages.remove(DEFAULT_LANG) + languages.remove(TLDR_LANG) except ValueError: pass - languages.insert(0, DEFAULT_LANG) - else: - languages.append('en') + languages.insert(0, TLDR_LANG) + if "en" not in languages: + languages.append(None) return languages From 29cd644b8d1a37e7c904998b5eb8dcf6334c1266 Mon Sep 17 00:00:00 2001 From: columbarius Date: Mon, 22 Jun 2020 00:02:38 +0200 Subject: [PATCH 3/7] Remove TLDR_LANGUAGE env var --- tldr.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tldr.py b/tldr.py index 01260e4..8358e1c 100755 --- a/tldr.py +++ b/tldr.py @@ -27,11 +27,6 @@ 'https://tldr-pages.github.io/assets/tldr.zip' ) -TLDR_LANG = os.environ.get( - 'TLDR_LANGUAGE', - None -) - DEFAULT_LANG = os.environ.get( 'LANG', 'C' @@ -172,12 +167,6 @@ def get_language_list(): languages.append(DEFAULT_LANG) else: languages = [] - if TLDR_LANG is not None: - try: - languages.remove(TLDR_LANG) - except ValueError: - pass - languages.insert(0, TLDR_LANG) if "en" not in languages: languages.append(None) return languages From 0646569d369cc62683101d632290d4b08d019915 Mon Sep 17 00:00:00 2001 From: columbarius Date: Mon, 20 Jul 2020 11:42:57 +0200 Subject: [PATCH 4/7] Add POSIX case --- tldr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tldr.py b/tldr.py index 8358e1c..3d698b1 100755 --- a/tldr.py +++ b/tldr.py @@ -32,7 +32,7 @@ 'C' ).split('_')[0] -if DEFAULT_LANG == 'C': +if DEFAULT_LANG == 'C' or DEFAULT_LANG == 'POSIX': DEFAULT_LANG = None USE_CACHE = int(os.environ.get('TLDR_CACHE_ENABLED', '1')) > 0 @@ -160,14 +160,14 @@ 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 == ''), languages) + 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) else: languages = [] - if "en" not in languages: + if 'en' not in languages: languages.append(None) return languages From 3cb19543c5e67e719b0f8bfd49cabc8ae3770eb2 Mon Sep 17 00:00:00 2001 From: columbarius Date: Tue, 21 Jul 2020 14:19:12 +0200 Subject: [PATCH 5/7] Adapt README.md --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b73e1cc..c42cfdb 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,6 @@ You can configure the behavior and output of the `tldr` client by setting enviro export TLDR_CACHE_MAX_AGE=720 export TLDR_PAGES_SOURCE_LOCATION="https://raw.githubusercontent.com/tldr-pages/tldr/master/pages" export TLDR_DOWNLOAD_CACHE_LOCATION="https://tldr-pages.github.io/assets/tldr.zip" - export TLDR_LANGUAGE="en" ### Cache @@ -104,16 +103,16 @@ Any of the values of above may be omitted. For example, you can do similar thing * `TLDR_COLOR_PARAMETER="red on_yellow underline"` for underlined red text on yellow background * `TLDR_COLOR_NAME="bold underline"` for default system font and background colors with underline and bolded effects -### Language +### Language The language that tldr will use is dependent on a number of factors. If you specify a language via the `--language` flag, tldr will attempt to use that language and only that language. Otherwise, it will -default to language set using either `TLDR_LANGUAGE` before falling back to `LANG` (ignoring the value `C`). -If neither are set, then tldr will always attempt to get the `en` page. Finally, if `LANGUAGES` is set, it uses -this as the priority list to try languages in, with the exception that it will attempt `TLDR_LANGUAGE` and `LANG` -first, and if neither are set, will use `en` last (assuming it does not already appear somewhere in `LANGUAGES`). +default to language set using `LANGUAGE` and `LANG` (ignoring the value `C` and `POSIX`). +If neither are set, then tldr will always attempt to get the `en` page. Finally, if `LANG` is set, it uses `LANGUAGE`, if set, +first as the priority list to try languages in, followed by `LANG` if not included in `LANGUAGE` +and `en` as fallback (assuming it does not already appear somewhere in `LANGUAGES` or `LANG`). All language values should be set to a value that follows [RFC 1766](https://tools.ietf.org/html/rfc1766.html), -with the special exception of `C` which is ignored. +with the special exception of `C` and `POSIX` which is ignored. ### Remote source From 77676da0047efd66c5d8498014b9b5f013322116 Mon Sep 17 00:00:00 2001 From: columbarius Date: Tue, 21 Jul 2020 14:22:56 +0200 Subject: [PATCH 6/7] Fix typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c42cfdb..b2edbb4 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ The language that tldr will use is dependent on a number of factors. If you spec default to language set using `LANGUAGE` and `LANG` (ignoring the value `C` and `POSIX`). If neither are set, then tldr will always attempt to get the `en` page. Finally, if `LANG` is set, it uses `LANGUAGE`, if set, first as the priority list to try languages in, followed by `LANG` if not included in `LANGUAGE` -and `en` as fallback (assuming it does not already appear somewhere in `LANGUAGES` or `LANG`). +and `en` as fallback (assuming it does not already appear somewhere in `LANGUAGE` or `LANG`). All language values should be set to a value that follows [RFC 1766](https://tools.ietf.org/html/rfc1766.html), with the special exception of `C` and `POSIX` which is ignored. From ee554df760289c5c9c33ef0c61929dc7e119b4f7 Mon Sep 17 00:00:00 2001 From: columbarius Date: Wed, 22 Jul 2020 16:33:36 +0200 Subject: [PATCH 7/7] Bump client_specification --- tldr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tldr.py b/tldr.py index 3d698b1..f5e37a0 100755 --- a/tldr.py +++ b/tldr.py @@ -15,7 +15,7 @@ import colorama # Required for Windows __version__ = "1.0.0" -__client_specification__ = "1.2" +__client_specification__ = "1.3" REQUEST_HEADERS = {'User-Agent': 'tldr-python-client'} PAGES_SOURCE_LOCATION = os.environ.get(