Skip to content

Commit 090c6dd

Browse files
pladariaPedro Ladaria
andauthored
chore(Playroom): set lang attribute in playroom previews (#1402)
WEB-2267 Requested by VIVO ### Example ![image](https://github.com/user-attachments/assets/264c3c4f-4691-4481-a01f-a05c1b24d320) Co-authored-by: Pedro Ladaria <pedro.jose.ladaria.linden@telefonica.com>
1 parent 2518790 commit 090c6dd

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

playroom/frame-component.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
TU_SKIN,
1818
MOVISTAR_SKIN,
1919
ESIMFLAG_SKIN,
20+
VIVO_SKIN,
21+
BLAU_SKIN,
2022
} from '../src';
2123

2224
import type {ThemeConfig} from '../src';
@@ -39,8 +41,30 @@ const ThemeOverriderContextProvider = ({children}: ThemeOverriderContextProvider
3941

4042
export const useOverrideTheme = (): OverrideTheme => React.useContext(ThemeOverriderContext);
4143

44+
/**
45+
* The language cannot be fully determined from the skin name because
46+
* some skins are used in multiple countries.
47+
*
48+
* This is a best effort.
49+
* The only OB that has shown interest in having their own lang is Vivo,
50+
*/
51+
const skinToLang: Record<string, string> = {
52+
[VIVO_NEW_SKIN]: 'pt-BR',
53+
[VIVO_SKIN]: 'pt-BR',
54+
[BLAU_SKIN]: 'de-DE',
55+
[TELEFONICA_SKIN]: 'es-ES',
56+
[MOVISTAR_SKIN]: 'es-ES',
57+
};
58+
4259
const App = ({children, skinName}: {children: React.ReactNode; skinName: string}) => {
4360
const {isModalOpen} = useModalState();
61+
const lang = skinToLang[skinName] || 'en';
62+
63+
React.useEffect(() => {
64+
// set lang attribute in html tag
65+
document.documentElement.lang = lang;
66+
}, [lang]);
67+
4468
const styles = `
4569
body {background: ${skinVars.colors.background}}
4670
@@ -54,18 +78,18 @@ const App = ({children, skinName}: {children: React.ReactNode; skinName: string}
5478
? 'body {font-family: "On Air"}'
5579
: ''
5680
}
57-
81+
5882
5983
*[class^='_1fu0koy1'] {
6084
display: none;
6185
}
6286
`;
6387

6488
return (
65-
<div lang="en" aria-hidden={isModalOpen}>
89+
<main lang={lang} aria-hidden={isModalOpen}>
6690
<style>{styles}</style>
6791
{children}
68-
</div>
92+
</main>
6993
);
7094
};
7195

0 commit comments

Comments
 (0)