@@ -115,21 +115,21 @@ type Props = {
115
115
translations ?: Translations ;
116
116
} ;
117
117
118
- const TranslationLabel = ( {
118
+ const getTranslationLabel = ( {
119
119
defaultLocaleId,
120
- locale ,
120
+ localeId ,
121
121
messages,
122
122
translation,
123
123
} : {
124
124
defaultLocaleId : React . Key ;
125
+ localeId : React . Key ;
125
126
messages : Messages ;
126
- locale : Item ;
127
127
translation : Translation ;
128
128
} ) => {
129
129
let displayType : DisplayType = 'warning' ;
130
- let label = messages . untranslated ;
130
+ let label : string = messages . untranslated ;
131
131
132
- if ( locale . id === defaultLocaleId ) {
132
+ if ( localeId === defaultLocaleId ) {
133
133
displayType = 'info' ;
134
134
label = messages . default ;
135
135
} else if ( translation ) {
@@ -144,28 +144,9 @@ const TranslationLabel = ({
144
144
}
145
145
}
146
146
147
- return (
148
- < >
149
- < span className = "sr-only" >
150
- { sub ( messages . option , [
151
- locale . displayName || locale . label ,
152
- label ,
153
- ] ) }
154
- </ span >
155
-
156
- < ClayLabel
157
- aria-hidden = "true"
158
- className = "c-ml-3"
159
- displayType = { displayType }
160
- >
161
- { label }
162
- </ ClayLabel >
163
- </ >
164
- ) ;
147
+ return { displayType, label} ;
165
148
} ;
166
149
167
- TranslationLabel . displayName = 'Label' ;
168
-
169
150
const Trigger = React . forwardRef < HTMLButtonElement > (
170
151
(
171
152
{
@@ -264,8 +245,22 @@ const ClayLanguagePicker = ({
264
245
triggerMessage = { messages . trigger }
265
246
>
266
247
{ ( locale ) => {
248
+ const translationLabel = getTranslationLabel ( {
249
+ defaultLocaleId : defaultLocaleId || locales [ 0 ] ! . id ,
250
+ localeId : locale . id ,
251
+ messages,
252
+ translation : translations [ locale . label ] ! ,
253
+ } ) ;
254
+
267
255
return (
268
- < Option key = { locale . id } textValue = { locale . label } >
256
+ < Option
257
+ aria-label = { sub ( messages . option , [
258
+ locale . displayName || locale . label ,
259
+ translationLabel . label ,
260
+ ] ) }
261
+ key = { locale . id }
262
+ textValue = { locale . label }
263
+ >
269
264
< ClayLayout . ContentRow containerElement = "span" >
270
265
< ClayLayout . ContentCol
271
266
containerElement = "span"
@@ -286,17 +281,23 @@ const ClayLanguagePicker = ({
286
281
{ hasTranslations ? (
287
282
< ClayLayout . ContentCol containerElement = "span" >
288
283
< ClayLayout . ContentSection >
289
- < TranslationLabel
290
- defaultLocaleId = {
291
- defaultLocaleId ||
292
- locales [ 0 ] ! . id
293
- }
294
- locale = { locale }
295
- messages = { messages }
296
- translation = {
297
- translations [ locale . label ] !
284
+ < ClayLabel
285
+ aria-hidden = "true"
286
+ className = "c-ml-3"
287
+ displayType = {
288
+ translationLabel . displayType
298
289
}
299
- />
290
+ >
291
+ { translationLabel . label }
292
+
293
+ < span className = "sr-only" >
294
+ { sub ( messages . option , [
295
+ locale . displayName ||
296
+ locale . label ,
297
+ translationLabel . label ,
298
+ ] ) }
299
+ </ span >
300
+ </ ClayLabel >
300
301
</ ClayLayout . ContentSection >
301
302
</ ClayLayout . ContentCol >
302
303
) : null }
0 commit comments