Skip to content

Commit

Permalink
Fallback to project type message on unknown types (modrinth#1470)
Browse files Browse the repository at this point in the history
This commit adds a fallback to getProjectTypeMessage function to return
a generic project type whenever it encounters an unknown project type,
ensuring there are no errors when the new project types are added.
  • Loading branch information
brawaru authored Dec 6, 2023
1 parent 2d14e56 commit b453e2c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion utils/i18n-project-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,23 @@ const projectTypeMessages = defineMessages({
id: 'project-type.shader.plural',
defaultMessage: 'Shaders',
},
project: {
id: 'project-type.project.singular',
defaultMessage: 'Project',
},
projects: {
id: 'project-type.project.plural',
defaultMessage: 'Projects',
},
})

type ExtractSingulars<K extends string> = K extends `${infer T}s` ? T : never

type ProjectType = ExtractSingulars<keyof typeof projectTypeMessages>

export function getProjectTypeMessage(type: ProjectType, plural = false) {
return projectTypeMessages[`${type}${plural ? 's' : ''}`]
return (
projectTypeMessages[`${type}${plural ? 's' : ''}`] ??
projectTypeMessages[`project${plural ? 's' : ''}`]
)
}

0 comments on commit b453e2c

Please sign in to comment.