Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@argl
Copy link
Contributor

@argl argl commented Aug 13, 2025

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

@argl argl marked this pull request as ready for review August 13, 2025 15:57
@argl argl requested a review from LeoMcA August 13, 2025 15:59
Copy link
Contributor

@caugner caugner left a 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>,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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

@argl argl requested a review from caugner August 25, 2025 11:20
Copy link
Member

@LeoMcA LeoMcA left a 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>,
Copy link
Member

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)
Copy link
Member

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

@caugner caugner changed the title Make the locale argument to RariApi::link optional, fix its locale logic chore(api): make locale optional for RariApi::link + fix logic Aug 26, 2025
@caugner caugner changed the title chore(api): make locale optional for RariApi::link + fix logic chore(api): apply locale passed to RariApi::link + make optional Aug 26, 2025
@caugner caugner merged commit 6c24ea1 into main Aug 26, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

{{APIListAlpha}} cannot deal with translated pages

3 participants