# -*- coding: utf-8 -*-
"""Localization helper — wraps xbmcaddon getLocalizedString with .format() support."""

import xbmcaddon
from .cd2_constants import ADDON_ID

_addon = None


def _get_addon():
    global _addon
    if _addon is None:
        _addon = xbmcaddon.Addon(ADDON_ID)
    return _addon


def _(string_id, *args):
    """Get localized string by ID, optionally format with args.
    Usage: _(32001) or _(32013, name="Aliyun")
    """
    s = _get_addon().getLocalizedString(string_id)
    if args:
        return s.format(*args)
    return s


def __(string_id, **kwargs):
    """Get localized string with named format args.
    Usage: __(32111, user="Someone")
    """
    s = _get_addon().getLocalizedString(string_id)
    if kwargs:
        return s.format(**kwargs)
    return s
