-
Notifications
You must be signed in to change notification settings - Fork 21
chore(api): apply locale passed to RariApi::link + make optional #287
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed to submit my review.
tl;dr I think we should simply pass in the link with the current locale for now: #294
| pub fn link( | ||
| link: &str, | ||
| locale: Locale, | ||
| locale: Option<Locale>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yagni: We don't seem to pass None anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a hint from Florian, for consistency of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a necessary inclusion: otherwise we have no way of keeping the locale in the url untouched
| ) -> Result<String, DocError> { | ||
| let mut out = String::new(); | ||
| let (url, locale) = if let Some(locale) = locale { | ||
| (link.strip_prefix("/en-US/docs").unwrap_or(link), locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we strip this prefix in api_list_alpha.rs instead? We probably shouldn't pass in a link with a locale here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are numerous calls for RariApi::link in the code base. I have tried to change all of them to not pass in the locale in the url, but this would be a deep change that also muddles the water between url and slug terms. This version solves the issue, I also run a complete output diff before and after the change, making sure that nothing unexpected has been changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't pass in a link with a locale here.
I disagree, I don't think we should concern ourselves with locale stripping in every single macro implementation if we can have a generic function which does it for us - which this change adds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this change: I like the flexibility this gives to the RariApi::link function
| pub fn link( | ||
| link: &str, | ||
| locale: Locale, | ||
| locale: Option<Locale>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a necessary inclusion: otherwise we have no way of keeping the locale in the url untouched
| ) -> Result<String, DocError> { | ||
| let mut out = String::new(); | ||
| let (url, locale) = if let Some(locale) = locale { | ||
| (link.strip_prefix("/en-US/docs").unwrap_or(link), locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't pass in a link with a locale here.
I disagree, I don't think we should concern ourselves with locale stripping in every single macro implementation if we can have a generic function which does it for us - which this change adds
Description
The
{{APIListAlpha}}macro was handling locale incorrectly (always returning en-US links, regardless of the presence of a translated page).Motivation
Repairing a leftover regression after moving to rari, made explicit in this Issue.
Additional details
While fixing the logic, it was decided to make the function shape more in line with the rest of the internal API, by passing in an optional locale to
RariApi::link. Concequently, all callers of the function had to be changed as well.Related issues and pull requests
fixes #286