JPKCom Simple Lang

frontend-language.php

Frontend Language Override

Handles switching the locale in the frontend based on post language settings.

Tags
since
1.0.0

Table of Contents

Functions

jpkcom_simplelang_get_language_code()  : string
Convert locale to language code
jpkcom_simplelang_get_bcp47()  : string
Convert a WordPress locale to a BCP 47 language tag
jpkcom_simplelang_get_current_language()  : string|null
Get current frontend language

Functions

jpkcom_simplelang_get_language_code()

Convert locale to language code

jpkcom_simplelang_get_language_code(string $locale) : string

Converts a locale string (e.g., de_DE) to a language code (e.g., de).

Kept for backwards compatibility. For markup that needs a language tag use jpkcom_simplelang_get_bcp47() instead — a bare subtag cannot express de-DE versus de-AT, and hreflang needs that distinction.

Parameters
$locale : string

The locale string.

Tags
since
1.0.0
Return values
string

The language code.

jpkcom_simplelang_get_bcp47()

Convert a WordPress locale to a BCP 47 language tag

jpkcom_simplelang_get_bcp47(string $locale) : string

de_DE becomes de-DE, en_US becomes en-US, ca stays ca. WordPress variant suffixes carry no BCP 47 meaning and are dropped, so de_DE_formal and de_CH_informal become de-DE and de-CH, and pt_PT_ao90 becomes pt-PT — a formal and an informal German page are the same language and region as far as a search engine is concerned.

Parameters
$locale : string

The WordPress locale (e.g. 'de_DE', 'de_DE_formal').

Tags
since
1.2.9
Return values
string

The BCP 47 tag (e.g. 'de-DE').

jpkcom_simplelang_get_current_language()

Get current frontend language

jpkcom_simplelang_get_current_language() : string|null

Returns the currently active language for the frontend.

Tags
since
1.0.0
Return values
string|null

The current language locale or null if using site default.

On this page

Search results