Closed laurmaedje closed 1 week ago
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
Or does anyone have some other ideas?
Description
When writing
#set text(lang: "en-gb")
, we should have a hint that you should use theregion
field instead.Use Case
Helps people fix the problem.