You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hint for language-region pair where language is expected #4142
Hi, I wonder if this diagnostics shall be implemented in Lang::from_str. I see current diagnostics information "expected two or three letter language code (ISO 639-1/2/3)" comes from there.
Unfortunately, the casting infrastructure doesn't support hints yet (FromValue always returns a StrResult). So, I think the only place we can do this at the moment is by augmenting the text.lang with a #[parse] annotation (you can search the codebase to see how it works).
I am thinking about when to hint something like "you should use region field". Here are some options I thought out:
Op1: The arg contains -
Op2: Op1 + the length of arg.split('-') is 2
Op3: Op2 + arg[0] can be parsed into Lang & arg[1] can be parsed into Region
Activity
Coekjan commentedon May 16, 2024
Hi, I wonder if this diagnostics shall be implemented in
Lang::from_str. I see current diagnostics information "expected two or three letter language code (ISO 639-1/2/3)" comes from there.laurmaedje commentedon May 16, 2024
Unfortunately, the casting infrastructure doesn't support hints yet (
FromValuealways returns aStrResult). So, I think the only place we can do this at the moment is by augmenting thetext.langwith a#[parse]annotation (you can search the codebase to see how it works).Coekjan commentedon May 18, 2024
I am thinking about when to hint something like "you should use
regionfield". Here are some options I thought out:Op1: The
argcontains-Op2: Op1 + the length of
arg.split('-')is 2Op3: Op2 +
arg[0]can be parsed intoLang&arg[1]can be parsed intoRegionOr does anyone have some other ideas?