מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init history"v5.5.1029.6.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-08-23עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
Documentation: getLocaleLang Function in intlayer
Description
The getLocaleLang function extracts the language code from a locale string. It supports locales with or without country codes. If no locale is provided, it defaults to returning an empty string.
Parameters
locale?: Locales- Description: The locale string (e.g.,
Locales.ENGLISH_UNITED_STATES,Locales.FRENCH_CANADA) from which the language code is extracted. - Type:
Locales(optional)
- Description: The locale string (e.g.,
Returns
- Type:
string - Description: The language code extracted from the locale. If the locale is not provided, it returns an empty string (
'').
Example Usage
Extracting Language Codes:
typescript
העתקת קוד
העתקת הקוד ללוח
import { getLocaleLang, Locales } from "intlayer";
getLocaleLang(Locales.ENGLISH_UNITED_STATES); // Output: "en"
getLocaleLang(Locales.ENGLISH); // Output: "en"
getLocaleLang(Locales.FRENCH_CANADA); // Output: "fr"
getLocaleLang(Locales.FRENCH); // Output: "fr"
Edge Cases
No Locale Provided:
- The function returns an empty string when
localeisundefined.
- The function returns an empty string when
Malformed Locale Strings:
- If the
localedoes not follow thelanguage-countryformat (e.g.,Locales.ENGLISH-US), the function safely returns the part before'-'or the entire string if no'-'is present.
- If the
