i18n
i18n copied to clipboard
Support defining <html> [lang] attribute BCP 47 code separately
Version
nuxt-i18n: 6.13.0-beta.0 nuxt: 2.12.2
Nuxt configuration
mode:
- [x] universal
- [ ] spa
Nuxt-i18n configuration
If relevant, please include the configuration you are using for this module.
For example:
[
'nuxt-i18n',
{
seo: false,
lazy: true,
langDir: 'lang/',
defaultLocale: 'en',
locales: [
{
code: 'en',
file: 'en-US.js',
iso: 'en_US'
},
{
code: 'da',
file: 'da-DK.js',
iso: 'da_DK'
}
],
What is Expected?
(the `code` parameter of `locales`)What is actually happening?
(the `iso` parameter of `locales`)https://web.dev/html-lang-valid/?utm_source=lighthouse&utm_medium=lr
I haven't dug too much into it but I think that, while the standards for ISO codes (ISO 639-1 + optional ISO 3166-1) and lang attribute (BCP 47) are different, typically ISO codes should not be invalid in the context of the lang attribute. I think your values for iso are actually invalid as those suppose to have a dash, not underscore in them (see locales documentation at https://nuxt-community.github.io/nuxt-i18n/options-reference.html).
Using code wouldn't be correct as that one doesn't follow any standard and can be arbitrary chosen by the user. It can be just a, b, c if user chooses so.
So while using ISO codes might not be ideal, it should not be invalid.
I'd have to study BCP 47 spec to see what is the ideal value to use and maybe introduce new property for it.
I see - it seems as though the list is here: http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry - and I don't find either da-DK or en-US
Also from: https://www.w3.org/International/articles/language-tags/#overview
The golden rule when creating language tags is to keep the tag as short as possible. Avoid region, script or other subtags except where they add useful distinguishing information. For instance, use ja for Japanese and not ja-JP, unless there is a particular reason that you need to say that this is Japanese as spoken in Japan, rather than elsewhere.
I see - it seems as though the list is here: http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry - and I don't find either da-DK or en-US
I can see entries like these there:
Type: region
Subtag: DK
Description: Denmark
Added: 2005-10-16
Type: region
Subtag: US
Description: United States
Added: 2005-10-16
The golden rule when creating language tags is to keep the tag as short as possible.
Yes, as I said, it might not be ideal to use ISO code. Not invalid though.
I think that a new property would need to be introduced for this as it's hard to determine what's "useful" automatically. It depends on what languages are supported by the site.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
i'm willing to work on it. @rchl do you mean introducing a lang property to be used if specified instead of seo for the lang attribute?
i'm willing to work on it. @rchl do you mean introducing a
langproperty to be used if specified instead ofseofor the lang attribute?
(You meant iso rather than seo)
Yes, but I feel the lang property is too likely to conflict with what people are using today. In fact, I use lang in all my projects to denote the language of the locale (so for example using lang=es for both es-AR, es-CL and es-CO locales).
lang-bcp maybe?
Thinking more about it, I guess my lang value might be even correct for the lang HTML attribute and possibly better than using iso value.
I guess the big problem with those BCP47 codes is that they are fairly complex and it's not always easy to tell what's the best value to use. Not sure how many users will really benefit from it...
hmm, the problem is that it depends on user and what he knows about codes or what's correct and what's not, but definitely adding lang attribute would be much better than lang-bcp i think, users can relate better to lang IMO.
and as far as lang wouldn't be a problem if used in the lang attr, the conflicts are rare. I'm just wondering if someone wants to use the iso not lang and lang is specified for any other reason, he has no choice.
EDIT: maybe user shouldn't has a choice, as lang-bcp is better to be used.
Hmm, lang-bcp seems better also. After a bit of thinking, this's the current standard.
if someone doesn't know/care about the standard he can use it for specifying the lang normally.
in the same-time, this avoids the conflicts with people who're using lang today. and we can ONLY then depend on lang-bcp for the lang attr.
EDIT: If you feel like that this need to be discussed with more people, maybe we can leave it for now.