Skip to content
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

feat: add locale header to request to fetch content based on system locale if possible #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion archivy/models.py
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urljoin

import frontmatter
import locale
import requests
import validators
from attr import attrs, attrib
Expand Down Expand Up @@ -92,7 +93,15 @@ def process_bookmark_url(self):
return None

try:
url_request = requests.get(self.url)
try:
lc = locale.getdefaultlocale()[0].replace('_', '-')
Copy link
Member

Choose a reason for hiding this comment

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

Does this work for every locale (replacing _ with -)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I hope it works, is there any case it doesnt?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure, I don't know much about locales and how it works with web requests, so I was asking since you opened the PR.

I just want to make sure the code we merge in works well :)

if lc == "C":
# fall back to en-US
lc == "en-US"
headers = {"Accept-Language": lc}
except Exception:
headers = None
url_request = requests.get(self.url, headers=headers)
except Exception:
flash(f"Could not retrieve {self.url}\n", "error")
self.wipe()
Expand Down