# #region _validate_bcp47 [C:2] [TYPE Function] [SEMANTICS validation, bcp47, language]
# @BRIEF Validate that a language tag is a non-empty BCP-47 string.

import re as _re


def _validate_bcp47(tag: str, field_name: str) -> None:
    """Validate that tag is a non-empty BCP-47 string (basic check)."""
    if not tag or not tag.strip():
        raise ValueError(f"{field_name} must be a non-empty BCP-47 language tag")
    tag = tag.strip()
    if not _re.match(r'^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$', tag):
        raise ValueError(
            f"{field_name} is not a valid BCP-47 tag: '{tag}'. "
            "Expected format like 'en', 'ru', 'zh-CN', 'pt-BR'."
        )
# #endregion _validate_bcp47
