docs: filterAvailableLocales (#11031)

Adding documentation and tests missing in PR #11007

---------

Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
Co-authored-by: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com>
This commit is contained in:
Dan Ribbens
2025-02-12 14:48:12 -05:00
committed by GitHub
parent 6bfa66c9ff
commit 3131dba039
4 changed files with 52 additions and 8 deletions

View File

@@ -414,9 +414,16 @@ export default buildConfigWithDefaults({
},
],
localization: {
filterAvailableLocales: ({ locales }) => {
return locales.filter((locale) => locale.code !== 'xx')
},
defaultLocale,
fallback: true,
locales: [
{
code: 'xx',
label: 'FILTERED',
},
{
code: defaultLocale,
label: 'English',

View File

@@ -97,7 +97,7 @@ describe('Localization', () => {
// })
})
describe('localizer', async () => {
describe('localizer', () => {
test('should show localizer controls', async () => {
await page.goto(url.create)
await expect(page.locator('.localizer.app-header__localizer')).toBeVisible()
@@ -105,6 +105,13 @@ describe('Localization', () => {
await expect(page.locator('.localizer .popup.popup--active')).toBeVisible()
})
test('should filter locale with filterAvailableLocales', async () => {
await page.goto(url.create)
await expect(page.locator('.localizer.app-header__localizer')).toBeVisible()
await page.locator('.localizer >> button').first().click()
await expect(page.locator('.localizer .popup.popup--active')).not.toContainText('FILTERED')
})
test('should disable control for active locale', async () => {
await page.goto(url.create)
@@ -472,7 +479,7 @@ describe('Localization', () => {
await runCopy(page)
await expect(page.locator('#field-title')).toHaveValue(title)
const regexPattern = new RegExp(`locale=es`)
const regexPattern = /locale=es/
await expect(page).toHaveURL(regexPattern)
await openCopyToLocaleDrawer(page)

View File

@@ -68,7 +68,7 @@ export interface Config {
'global-array': GlobalArraySelect<false> | GlobalArraySelect<true>;
'global-text': GlobalTextSelect<false> | GlobalTextSelect<true>;
};
locale: 'en' | 'es' | 'pt' | 'ar' | 'hu';
locale: 'xx' | 'en' | 'es' | 'pt' | 'ar' | 'hu';
user: User & {
collection: 'users';
};