Skip to content

Conversation

@malsadev
Copy link

@malsadev malsadev commented Feb 4, 2026

Issue: #5365

Pipeline build is failing because this PR is dependent on: LemmyNet/lemmy-translations#246

Nortification feed testing:

Modlog feed testing:

Test fallback language:

req: &HttpRequest,
context: &web::Data<LemmyContext>,
) -> Result<Lang, Error> {
let jwt = read_auth_token(&req)?;
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to read Accept-Language HTTP header as well for the language.

@malsadev malsadev marked this pull request as ready for review February 9, 2026 05:04
@Nutomic
Copy link
Member

Nutomic commented Feb 9, 2026

You dont need to wait for the translations to be merged. Instead do cd crates/email/translations/, then git checkout *your-branch*. Go back to main repo path, then commit the changed submodule version.

};

for client_lang in client_langs.ranked() {
let lang_id = match client_lang.item() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let lang_id = match client_lang.item() {
match client_lang.item()
.map(|l| LanguageId::new(lang.primary_language()))
.map(|l| Lang::from_language_id(&lang_id)) {
Some(l) => return l,
None => continue,
}

No need for multiple match statements this way,

}

fn negotiate_lang(req: &HttpRequest) -> Option<Lang> {
let client_langs = match req.headers().get(ACCEPT_LANGUAGE) {
Copy link
Member

@Nutomic Nutomic Feb 9, 2026

Choose a reason for hiding this comment

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

No need for match, use req.headers().get(ACCEPT_LANGUAGE)? to return None automatically.

.split(',')
.filter_map(|hv| hv.parse().ok())
.collect(),
),
Copy link
Member

Choose a reason for hiding this comment

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

Should work with let langs: AcceptLanguage = header.parse()? or similar.

context: &web::Data<LemmyContext>,
) -> Result<Lang, Error> {
let jwt = read_auth_token(&req)?;
let lang;
Copy link
Member

Choose a reason for hiding this comment

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

In rust you can return data from blocks.

So do

let lang = if let Some(jwt) = jwt {
...

lang
}

Also what IDE are you using? I recommend using either helix or vim with rust-anaylzer, or jetbrains.

context: &web::Data<LemmyContext>,
) -> Result<Lang, Error> {
let jwt = read_auth_token(&req)?;
let lang;
Copy link
Member

Choose a reason for hiding this comment

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

In rust you can return data from blocks.

So do

let lang = if let Some(jwt) = jwt {
...
}

Also what IDE are you using? I recommend using either helix or vim with rust-anaylzer, or jetbrains.

.filter_map(|hv| hv.parse().ok())
.collect(),
),
None => return None,
Copy link
Member

Choose a reason for hiding this comment

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

Don't return from blocks like this. You should probably refactor this entire thing as an if let block:

if let Some(client_langs) = req.headers().get(ACCEPT_LANGUAGE) {

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.

3 participants