Skip to content

Commit

Permalink
feat: enable internationalization overwriting and theme patching in r…
Browse files Browse the repository at this point in the history
…eact.main.tsx

Refs: #7144
  • Loading branch information
deleonio committed Dec 5, 2024
1 parent e9815db commit 812a91d
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions packages/samples/react/src/react.main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import type { Generic } from 'adopted-style-sheets';

type Theme = Generic.Theming.RegisterPatch<string, string, string>;

const ENABLE_I18N_OVERWRITING =
process.env.ENABLE_I18N_OVERWRITING === 'true' || new URL('https://x' + location.hash.substring(1)).searchParams.has('enableI18nOverwriting');

const ENABLE_THEME_PATCHING =
process.env.ENABLE_THEME_PATCHING === 'true' || new URL('https://x' + location.hash.substring(1)).searchParams.has('enableThemePatching');

const ENABLE_TAG_NAME_TRANSFORMER =
process.env.ENABLE_TAG_NAME_TRANSFORMER === 'true' || new URL('https://x' + location.hash.substring(1)).searchParams.has('enableTagNameTransformer');

Expand Down Expand Up @@ -58,18 +64,20 @@ void (async () => {
/**
* You can add your own translations here.
*/
translations: new Set([
(t) =>
t('en', {
// https://github.com/public-ui/kolibri/blob/develop/packages/components/src/locales/en.ts
'kol-error': 'Tiny error!',
}),
(t) =>
t('de', {
// https://github.com/public-ui/kolibri/blob/develop/packages/components/src/locales/de.ts
'kol-error': 'Kleiner Fehler!',
}),
]),
translations: ENABLE_I18N_OVERWRITING
? new Set([
(t) =>
t('en', {
// https://github.com/public-ui/kolibri/blob/develop/packages/components/src/locales/en.ts
'kol-error': 'Tiny error!',
}),
(t) =>
t('de', {
// https://github.com/public-ui/kolibri/blob/develop/packages/components/src/locales/de.ts
'kol-error': 'Kleiner Fehler!',
}),
])
: undefined,
transformTagName: ENABLE_TAG_NAME_TRANSFORMER ? tagNameTransformer : undefined,
environment: process.env.NODE_ENV === 'development' ? 'development' : 'production',
},
Expand All @@ -78,22 +86,24 @@ void (async () => {
/**
* You should patch the theme after the components and your default theme are registered.
*/
KoliBriDevHelper.patchTheme(
'default',
{
'KOL-SPIN': `
if (ENABLE_THEME_PATCHING) {
KoliBriDevHelper.patchTheme(
'default',
{
'KOL-SPIN': `
.bg-spin-2 {
background-color: red;
}
.bg-spin-3 {
background-color: gold;
}
`,
},
{
append: true,
},
);
},
{
append: true,
},
);
}

console.info('bootstap is initialized: ', isInitialized());
} catch (error) {
Expand Down

0 comments on commit 812a91d

Please sign in to comment.