Skip to content

Commit

Permalink
feat: changed minimum of 2 locales to minimum of 1 (#6406)
Browse files Browse the repository at this point in the history
* feat: changed minimum of 2 locales to minimum of 1

* feat: only show i18n editor toggle if there are multiple locales
  • Loading branch information
dfdez authored Aug 23, 2023
1 parent 514984a commit f3a30b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ class EditorInterface extends Component {

const previewEnabled = isPreviewEnabled(collection, entry);

const collectionI18nEnabled = hasI18n(collection);
const { locales, defaultLocale } = getI18nInfo(this.props.collection);
const collectionI18nEnabled = hasI18n(collection) && locales.length > 1;
const editorProps = {
collection,
entry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,19 @@ describe('config', () => {
}).toThrowError(`'i18n.locales[1]' must NOT have more than 10 characters`);
});

it('should throw error when locales is less than 1 items', () => {
expect(() => {
validateConfig(
merge({}, validConfig, {
i18n: {
structure: 'multiple_folders',
locales: [],
},
}),
);
}).toThrowError(`'i18n.locales' must NOT have fewer than 1 items`);
});

it('should allow valid locales strings', () => {
expect(() => {
validateConfig(
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-core/src/constants/configSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const i18n = {
structure: { type: 'string', enum: Object.values(I18N_STRUCTURE) },
locales: {
type: 'array',
minItems: 2,
minItems: 1,
items: localeType,
uniqueItems: true,
},
Expand Down

0 comments on commit f3a30b5

Please sign in to comment.