init commit for iPAL-kit plugin
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { I18nConfig, LocaleDefinition } from './types.js'
|
||||
|
||||
/**
|
||||
* Returns all configured locale codes.
|
||||
*/
|
||||
export function getLocaleCodes(config: I18nConfig): string[] {
|
||||
return config.locales.map((locale) => locale.code)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default locale code.
|
||||
*/
|
||||
export function getDefaultLocale(config: I18nConfig): string {
|
||||
return config.defaultLocale
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is a valid configured locale code.
|
||||
*/
|
||||
export function isValidLocale(code: string, config: I18nConfig): boolean {
|
||||
return config.locales.some((locale) => locale.code === code)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full locale definition for a given code, or undefined if not found.
|
||||
*/
|
||||
export function getLocaleDefinition(
|
||||
code: string,
|
||||
config: I18nConfig,
|
||||
): LocaleDefinition | undefined {
|
||||
return config.locales.find((locale) => locale.code === code)
|
||||
}
|
||||
Reference in New Issue
Block a user