Skip to content

Fetch individual translation archives for cache (#217) #218

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
Feb 23, 2024

Conversation

SaurabhDRao
Copy link
Contributor

Fetch individual translation archives for cache based on the environment variable configuration (#217)

Copy link
Member

@kbdharun kbdharun left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks for your contribution.

Copy link
Member

@acuteenvy acuteenvy left a comment

Choose a reason for hiding this comment

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

This works, but it downloads only the language set in LANG or TLDR_LANGUAGE - LANGUAGE is ignored. Also, it doesn't always download English, and that causes the client to download a single page from GitHub when a translation is not available. Is this expected?

@kbdharun
Copy link
Member

Hi @SaurabhDRao, Any updates on this?

@SaurabhDRao
Copy link
Contributor Author

I am extremely sorry, as I don't remember seeing these comments earlier.

Anyways, from what I checked, LANGUAGE variable is supposed to hold a list of user preferred languages and I believe what you are asking is to download the data for all the languages that are set in LANGUAGE variable ?

And also if a translation is unavailable for a language that is set in any of the language variables, we need to go ahead and download the data for English anyways ?

@kbdharun
Copy link
Member

I am extremely sorry, as I don't remember seeing these comments earlier.

No issues, thanks for your work.

Anyways, from what I checked, LANGUAGE variable is supposed to hold a list of user preferred languages and I believe what you are asking is to download the data for all the languages that are set in LANGUAGE variable ?

And also if a translation is unavailable for a language that is set in any of the language variables, we need to go ahead and download the data for English anyways ?

Yes, fetching only the languages specified in the environment variable, if a translated page isn't available display (fallback to) the English page with a warning that a translated page doesn't exist for the command in their language.

Additionally, the language flag when called with a language not set in the environment variable, we could add a check that says language should be set there or if it's done already, then refresh the cache using the update command.

Copy link
Member

@kbdharun kbdharun left a comment

Choose a reason for hiding this comment

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

Kinda curious, shouldn't lines 28-31 be updated for the same, instead of fetching the entire archive?

Reference:

DOWNLOAD_CACHE_LOCATION = os.environ.get(
    'TLDR_DOWNLOAD_CACHE_LOCATION',
    'https://tldr-pages.github.io/assets/tldr.zip'
)

@SaurabhDRao
Copy link
Contributor Author

Actually, I don't think that is required. If you have a look at line number 382

cache_location = f"{DOWNLOAD_CACHE_LOCATION[:-4]}-pages.{language}.zip"

you can see that the cache location will dynamically get updated as https://tldr-pages.github.io/assets/tldr-pages.{language}.zip

And since there is a call to get_language_list() which will return atleast "en" as a language, we would still be getting only language specific cache.

But one thing to note is that if the cache is being pulled from a different location, set in TLDR_DOWNLOAD_CACHE_LOCATION, it should follow similar path structure as in -pages.{language}.zip.
Do you think its fine or do you want me to make line 382 a bit more generic ?

Copy link
Member

@kbdharun kbdharun left a comment

Choose a reason for hiding this comment

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

Seems like linter is set to accept only 88 characters per line, feel free to update line 400, 401 for the same.

@kbdharun kbdharun requested a review from acuteenvy February 2, 2024 03:26
Copy link
Member

@vitorhcl vitorhcl left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contribution!

Copy link
Member

@acuteenvy acuteenvy left a comment

Choose a reason for hiding this comment

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

Works as expected.

@kbdharun kbdharun merged commit 9b683be into tldr-pages:main Feb 23, 2024
@kbdharun kbdharun added this to the 3.3.0 milestone Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted PRs which are eligible for hacktoberfest but won't get merged before 31st
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants