@@ -11,7 +11,7 @@ import type { I18nHeadOptions, I18nHeadMetaInfo, MetaAttrs, RoutingProxy } from
11
11
12
12
export function localeHead (
13
13
this : RoutingProxy ,
14
- { addDirAttribute = false , addSeoAttributes = false } : I18nHeadOptions = { }
14
+ { addDirAttribute = false , addSeoAttributes = false , identifierAttribute = 'hid' } : I18nHeadOptions = { }
15
15
) : I18nHeadMetaInfo {
16
16
const router = this . router
17
17
const i18n = this . i18n
@@ -46,16 +46,22 @@ export function localeHead(
46
46
metaObject . htmlAttrs . lang = currentLocaleIso
47
47
}
48
48
49
- addHreflangLinks . call ( this , locales as LocaleObject [ ] , i18n . __baseUrl , metaObject . link )
50
- addCanonicalLinks . call ( this , i18n . __baseUrl , metaObject . link , addSeoAttributes )
51
- addCurrentOgLocale ( currentLocale , currentLocaleIso , metaObject . meta )
52
- addAlternateOgLocales ( locales as LocaleObject [ ] , currentLocaleIso , metaObject . meta )
49
+ addHreflangLinks . call ( this , locales as LocaleObject [ ] , i18n . __baseUrl , metaObject . link , identifierAttribute )
50
+ addCanonicalLinks . call ( this , i18n . __baseUrl , metaObject . link , identifierAttribute , addSeoAttributes )
51
+ addCurrentOgLocale ( currentLocale , currentLocaleIso , metaObject . meta , identifierAttribute )
52
+ addAlternateOgLocales ( locales as LocaleObject [ ] , currentLocaleIso , metaObject . meta , identifierAttribute )
53
53
}
54
54
55
55
return metaObject
56
56
}
57
57
58
- function addHreflangLinks ( this : RoutingProxy , locales : LocaleObject [ ] , baseUrl : string , link : MetaAttrs ) {
58
+ function addHreflangLinks (
59
+ this : RoutingProxy ,
60
+ locales : LocaleObject [ ] ,
61
+ baseUrl : string ,
62
+ link : MetaAttrs ,
63
+ identifierAttribute : NonNullable < I18nHeadOptions [ 'identifierAttribute' ] >
64
+ ) {
59
65
const router = this . router
60
66
const { defaultLocale, strategy } = getI18nRoutingOptions ( router , this )
61
67
if ( strategy === STRATEGIES . NO_PREFIX ) {
@@ -84,7 +90,7 @@ function addHreflangLinks(this: RoutingProxy, locales: LocaleObject[], baseUrl:
84
90
const localePath = switchLocalePath . call ( this , mapLocale . code )
85
91
if ( localePath ) {
86
92
link . push ( {
87
- hid : `i18n-alt-${ iso } ` ,
93
+ [ identifierAttribute ] : `i18n-alt-${ iso } ` ,
88
94
rel : 'alternate' ,
89
95
href : toAbsoluteUrl ( localePath , baseUrl ) ,
90
96
hreflang : iso
@@ -96,7 +102,7 @@ function addHreflangLinks(this: RoutingProxy, locales: LocaleObject[], baseUrl:
96
102
const localePath = switchLocalePath . call ( this , defaultLocale )
97
103
if ( localePath ) {
98
104
link . push ( {
99
- hid : 'i18n-xd' ,
105
+ [ identifierAttribute ] : 'i18n-xd' ,
100
106
rel : 'alternate' ,
101
107
href : toAbsoluteUrl ( localePath , baseUrl ) ,
102
108
hreflang : 'x-default'
@@ -109,6 +115,7 @@ function addCanonicalLinks(
109
115
this : RoutingProxy ,
110
116
baseUrl : string ,
111
117
link : MetaAttrs ,
118
+ identifierAttribute : NonNullable < I18nHeadOptions [ 'identifierAttribute' ] > ,
112
119
seoAttributesOptions : I18nHeadOptions [ 'addSeoAttributes' ]
113
120
) {
114
121
const route = this . route
@@ -145,37 +152,47 @@ function addCanonicalLinks(
145
152
}
146
153
147
154
link . push ( {
148
- hid : 'i18n-can' ,
155
+ [ identifierAttribute ] : 'i18n-can' ,
149
156
rel : 'canonical' ,
150
157
href
151
158
} )
152
159
}
153
160
}
154
161
155
- function addCurrentOgLocale ( currentLocale : LocaleObject , currentLocaleIso : string | undefined , meta : MetaAttrs ) {
162
+ function addCurrentOgLocale (
163
+ currentLocale : LocaleObject ,
164
+ currentLocaleIso : string | undefined ,
165
+ meta : MetaAttrs ,
166
+ identifierAttribute : NonNullable < I18nHeadOptions [ 'identifierAttribute' ] >
167
+ ) {
156
168
const hasCurrentLocaleAndIso = currentLocale && currentLocaleIso
157
169
158
170
if ( ! hasCurrentLocaleAndIso ) {
159
171
return
160
172
}
161
173
162
174
meta . push ( {
163
- hid : 'i18n-og' ,
175
+ [ identifierAttribute ] : 'i18n-og' ,
164
176
property : 'og:locale' ,
165
177
// Replace dash with underscore as defined in spec: language_TERRITORY
166
178
content : hypenToUnderscore ( currentLocaleIso )
167
179
} )
168
180
}
169
181
170
- function addAlternateOgLocales ( locales : LocaleObject [ ] , currentLocaleIso : string | undefined , meta : MetaAttrs ) {
182
+ function addAlternateOgLocales (
183
+ locales : LocaleObject [ ] ,
184
+ currentLocaleIso : string | undefined ,
185
+ meta : MetaAttrs ,
186
+ identifierAttribute : NonNullable < I18nHeadOptions [ 'identifierAttribute' ] >
187
+ ) {
171
188
const localesWithoutCurrent = locales . filter ( locale => {
172
189
const localeIso = locale . iso
173
190
return localeIso && localeIso !== currentLocaleIso
174
191
} )
175
192
176
193
if ( localesWithoutCurrent . length ) {
177
194
const alternateLocales = localesWithoutCurrent . map ( locale => ( {
178
- hid : `i18n-og-alt-${ locale . iso } ` ,
195
+ [ identifierAttribute ] : `i18n-og-alt-${ locale . iso } ` ,
179
196
property : 'og:locale:alternate' ,
180
197
content : hypenToUnderscore ( locale . iso ! )
181
198
} ) )
0 commit comments