lib/i18n
Esta página aún no está disponible en tu idioma.
Type Aliases
Section titled “Type Aliases”UiComponentKeys
Section titled “UiComponentKeys”type UiComponentKeys = keyof UiTranslations["en"]["translations"];
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:44
Represents the keys of the UI component translations for the ‘en’ locale. This type is derived from the ‘translations’ property of the ‘UiTranslations’ interface for the ‘en’ locale (Source of truth), ensuring that only valid translation keys are used.
UiLanguageKeys
Section titled “UiLanguageKeys”type UiLanguageKeys = keyof UiTranslations;
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:37
Represents the keys of the UiTranslations type. This type is used to define the possible keys for UI language translations.
UiTranslations
Section titled “UiTranslations”type UiTranslations = typeof uiTranslations;
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:31
Represents the type of UI translations.
This type is derived from the structure of the uiTranslations
object.
Variables
Section titled “Variables”defaultLang
Section titled “defaultLang”const defaultLang: UiTranslationKey = 'en';
Defined in: studiocms/packages/studiocms/src/lib/i18n/config.ts:14
The default language for the StudioCMS app.
languageSelectorOptions
Section titled “languageSelectorOptions”const languageSelectorOptions: { key: "en" | "de" | "es" | "fr"; value: string; }[];
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:105
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
Section titled “Type declaration”key: "en" | "de" | "es" | "fr";
value: string;
Returns
Section titled “Returns”An array of objects representing language selector options.
Functions
Section titled “Functions”getCurrentURLPath()
Section titled “getCurrentURLPath()”function getCurrentURLPath(Astro: AstroGlobal): string
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:137
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
Section titled “Parameters”AstroGlobal
The global Astro object containing URL and request information.
Returns
Section titled “Returns”string
getLangFromUrl()
Section titled “getLangFromUrl()”function getLangFromUrl(url: URL): "en" | "de" | "es" | "fr"
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:118
Extracts the language key from the given URL’s pathname.
Parameters
Section titled “Parameters”URL
The URL object from which to extract the language key.
Returns
Section titled “Returns”"en"
| "de"
| "es"
| "fr"
The language key if it exists in the uiTranslations
, otherwise returns the default language key.
staticPaths()
Section titled “staticPaths()”function staticPaths(): { params: { locale: undefined | string; }; }[]
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:179
Example of how to use this i18n utils on a Static page
Returns
Section titled “Returns”{
params
: {
locale
: undefined
| string
;
};
}[]
An array of paths for all languages
Example
Section titled “Example”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()
Section titled “switchLanguage()”function switchLanguage(Astro: AstroGlobal): (languageKey: "en" | "de" | "es" | "fr") => string
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:157
Function to switch the language of the current page.
Parameters
Section titled “Parameters”AstroGlobal
The global Astro object.
Returns
Section titled “Returns”Function
Parameters
Section titled “Parameters”languageKey
Section titled “languageKey”"en"
| "de"
| "es"
| "fr"
Returns
Section titled “Returns”string
useTranslatedPath()
Section titled “useTranslatedPath()”function useTranslatedPath(lang: "en" | "de" | "es" | "fr"): (path: string, l?: string) => string
Defined in: studiocms/packages/studiocms/src/lib/i18n/index.ts:91
Returns a function that translates a given path based on the provided language.
Parameters
Section titled “Parameters”The language key to be used for translation.
"en"
| "de"
| "es"
| "fr"
Returns
Section titled “Returns”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
Section titled “Parameters”string
string
Returns
Section titled “Returns”string
useTranslations()
Section titled “useTranslations()”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:64
Retrieves a translation function for a given language and component.
Type Parameters
Section titled “Type Parameters”L
extends "en"
| "de"
| "es"
| "fr"
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:smtp"
| "@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"
| "@studiocms/dashboard:unverifiedEmail"
Parameters
Section titled “Parameters”L
The language key to use for translations.
component
Section titled “component”T
The component key to use for translations.
Returns
Section titled “Returns”Function
A function that takes a translation key and returns the corresponding translated string.
Parameters
Section titled “Parameters”keyof UiTranslationComponent
<L
, T
>
Returns
Section titled “Returns”UiTranslationComponent
<L
, T
>[keyof UiTranslationComponent
<L
, T
>]