lib/i18n
Type Aliases
'Read the “', Type Aliases, '” section'UiComponentKeys
'Read the “', UiComponentKeys, '” section'type UiComponentKeys = keyof UiTranslations["en-us"]["translations"];
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:42
Represents the keys of the UI component translations for the ‘en-us’ locale. This type is derived from the ‘translations’ property of the ‘UiTranslations’ interface for the ‘en-us’ locale (Source of truth), ensuring that only valid translation keys are used.
UiLanguageKeys
'Read the “', UiLanguageKeys, '” section'type UiLanguageKeys = keyof UiTranslations;
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:35
Represents the keys of the UiTranslations type. This type is used to define the possible keys for UI language translations.
UiTranslations
'Read the “', UiTranslations, '” section'type UiTranslations = typeof uiTranslations;
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:29
Represents the type of UI translations.
This type is derived from the structure of the uiTranslations
object.
Variables
'Read the “', Variables, '” section'languageSelectorOptions
'Read the “', languageSelectorOptions, '” section'const languageSelectorOptions: { key: "en-us"; value: string; }[];
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:103
Generates an array of language selector options from the uiTranslations
object.
Each option contains a key
and a value
where:
key
is a language key fromUiLanguageKeys
.value
is the display name of the language.
Type declaration
'Read the “', Type declaration, '” section'key: "en-us";
value: string;
An array of objects representing language selector options.
Functions
'Read the “', Functions, '” section'getCurrentURLPath()
'Read the “', getCurrentURLPath(), '” section'function getCurrentURLPath(Astro: AstroGlobal): string
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:135
Retrieves the current URL path, adjusting for language settings.
This function checks if the URL path includes ’/_server-islands’. If it does, it extracts the referer URL from the request headers and determines the current language from that URL. If the current language is the default language, it returns the pathname as is. Otherwise, it replaces the language segment in the pathname with ’/’.
If the URL path does not include ’/_server-islands’, it uses the Astro URL directly to determine the current language and adjust the pathname accordingly.
Parameters
'Read the “', Parameters, '” section'AstroGlobal
The global Astro object containing URL and request information.
string
getLangFromUrl()
'Read the “', getLangFromUrl(), '” section'function getLangFromUrl(url: URL): "en-us"
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:116
Extracts the language key from the given URL’s pathname.
Parameters
'Read the “', Parameters, '” section'URL
The URL object from which to extract the language key.
"en-us"
The language key if it exists in the uiTranslations
, otherwise returns the default language key.
staticPaths()
'Read the “', staticPaths(), '” section'function staticPaths(): { params: { locale: undefined | string; }; }[]
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:177
Example of how to use this i18n utils on a Static page
{
params
: {
locale
: undefined
| string
;
};
}[]
An array of paths for all languages
export async function getStaticPaths() { const paths = staticPaths(); return paths;}
If the default language is hidden, the paths for the default language will be generated without the language prefix while all extra languages will have the prefix. (e.g. When showDefaultLang
is false: /en/page
will be /page
and spanish will be /es/page
)
switchLanguage()
'Read the “', switchLanguage(), '” section'function switchLanguage(Astro: AstroGlobal): (languageKey: "en-us") => string
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:155
Function to switch the language of the current page.
Parameters
'Read the “', Parameters, '” section'AstroGlobal
The global Astro object.
Function
Parameters
'Read the “', Parameters, '” section'languageKey
'Read the “', languageKey, '” section'"en-us"
string
useTranslatedPath()
'Read the “', useTranslatedPath(), '” section'function useTranslatedPath(lang: "en-us"): (path: string, l?: string) => string
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:89
Returns a function that translates a given path based on the provided language.
Parameters
'Read the “', Parameters, '” section'"en-us"
The language key to be used for translation.
Function
A function that takes a path and an optional language key, and returns the translated path.
If the language key is not provided, the default language key is used.
If the language is the default language and showDefaultLang
is false, the original path is returned.
Otherwise, the path is prefixed with the language key.
Parameters
'Read the “', Parameters, '” section'string
string
string
useTranslations()
'Read the “', useTranslations(), '” section'function useTranslations<L, T>(lang: L, component: T): (key: keyof UiTranslationComponent<L, T>) => UiTranslationComponent<L, T>[keyof UiTranslationComponent<L, T>]
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:62
Retrieves a translation function for a given language and component.
Type Parameters
'Read the “', Type Parameters, '” section'• L extends "en-us"
• T extends
| "@studiocms/auth:login"
| "@studiocms/auth:signup"
| "@studiocms/auth:logout"
| "@studiocms/auth:oauth-stack"
| "@studiocms/dashboard:index"
| "@studiocms/dashboard:sidebar"
| "@studiocms/dashboard:profile"
| "@studiocms/dashboard:password-reset"
| "@studiocms/dashboard:configuration"
| "@studiocms/dashboard:user-mngmt-sidebar"
| "@studiocms/dashboard:user-mngmt-index"
| "@studiocms/dashboard:user-mngmt-edit"
| "@studiocms/dashboard:plugin-settings"
| "@studiocms/dashboard:content-sidebar"
| "@studiocms/dashboard:content-header"
| "@studiocms/dashboard:content-index"
| "@studiocms/dashboard:content-diff"
| "@studiocms/dashboard:content-folder"
| "@studiocms/dashboard:content-page"
| "@studiocms/dashboard:404"
Parameters
'Read the “', Parameters, '” section'L
The language key to use for translations.
component
'Read the “', component, '” section'T
The component key to use for translations.
Function
A function that takes a translation key and returns the corresponding translated string.
Parameters
'Read the “', Parameters, '” section'keyof UiTranslationComponent
<L
, T
>
UiTranslationComponent
<L
, T
>[keyof UiTranslationComponent
<L
, T
>]