aymericzip/intlayer-skills / skills/intlayer-usage
intlayer-usage
VerifiedProvides general guidelines for using Intlayer in any project. Use when the user asks to "get started with Intlayer", "declare content files", or understand the "project structure" for internationalization.
references/packages_intlayer_getLocaleLang.md
View on GitHub---
createdAt: 2025-08-23
updatedAt: 2026-09-27
priority: 5
title: getLocaleLang Function Documentation | intlayer
description: "Use getLocaleLang to extract the language code from a locale string such as en-US, with or without a country code."
keywords:
- getLocaleLang
- translation
- Intlayer
- intlayer
- Internationalization
- Documentation
- Next.js
- JavaScript
- React
slugs:
- doc
- packages
- intlayer
- getLocaleLang
history:
- version: 5.5.10
date: 2025-06-29
changes: "Init history"
author: aymericzip
---
# 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)
## 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 codeFormat={["typescript", "esm", "commonjs"]}
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 `locale` is `undefined`.
- **Malformed Locale Strings:**
- If the `locale` does not follow the `language-country` format (e.g., `Locales.ENGLISH-US`), the function safely returns the part before `'-'` or the entire string if no `'-'` is present.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |