מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Initial documentation"v7.1.016.11.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-11-16עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
Documentation: getPrefix Function in intlayer
Description
The getPrefix function determines the URL prefix for a given locale based on the routing mode configuration. It compares the locale with the default locale and returns an object containing three different prefix formats for flexible URL construction.
Key Features:
- Takes a locale as the first parameter (required)
- Optional
optionsobject withdefaultLocaleandmode - Returns an object with
prefix, andlocalePrefixproperties - Supports all routing modes:
prefix-no-default,prefix-all,no-prefix, andsearch-params - Lightweight utility for determining when to add locale prefixes
Function Signature
typescript
העתקת קוד
העתקת הקוד ללוח
Parameters
locale: Locales- Description: The locale to generate the prefix for. If the value is falsy (undefined, null, empty string), the function returns an empty string.
- Type:
Locales - Required: Yes
options?: object- Description: Configuration object for prefix determination.
- Type:
object Required: No (Optional)
options.defaultLocale?: Locales- Description: The default locale for the application. If not provided, uses the configured default locale from your project configuration.
- Type:
Locales - Default:
Project Configuration
options.mode?: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params'- Description: The URL routing mode for locale handling. If not provided, uses the configured mode from your project configuration.
- Type:
'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params' - Default:
Project Configuration - Modes:
prefix-no-default: Returns empty strings when locale matches default localeprefix-all: Returns prefix for all locales including defaultno-prefix: Returns empty strings (no prefix in URLs)search-params: Returns empty strings (locale in query parameters)
Returns
- Type:
GetPrefixResult - Description: An object containing three different prefix formats:
prefix: The path prefix with trailing slash (e.g.,'fr/','')localePrefix: The locale identifier without slashes (e.g.,'fr',undefined)
Example Usage
Basic Usage
typescript
העתקת קוד
העתקת הקוד ללוח
import { getPrefix, Locales } from "intlayer";
// Check prefix for English locale
getPrefix(Locales.ENGLISH, {
defaultLocale: Locales.ENGLISH,
mode: "prefix-all",
});
// Returns: { prefix: 'en/', localePrefix: 'en' }
// Check prefix for French locale
getPrefix(Locales.FRENCH, {
defaultLocale: Locales.ENGLISH,
mode: "prefix-no-default",
});
// Returns: { prefix: 'fr/', localePrefix: 'fr' }
Different Routing Modes
typescript
העתקת קוד
העתקת הקוד ללוח
Practical Example
typescript
העתקת קוד
העתקת הקוד ללוח
Related Functions
TypeScript
typescript
העתקת קוד
העתקת הקוד ללוח
