<?php

use App\Models\Translation;

if (!function_exists('trans_db')) {
    /**
     * Translate database content
     */
    function trans_db($group, $key, $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        return Translation::getTranslated($locale, $group, $key, $default);
    }
}

if (!function_exists('trans_blog')) {
    /**
     * Translate blog content
     */
    function trans_blog($blog, $field = 'title', $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        $key = is_object($blog) ? $blog->id : $blog;
        return Translation::getTranslated($locale, 'blogs', $key . '_' . $field, $default);
    }
}

if (!function_exists('trans_category')) {
    /**
     * Translate category content
     */
    function trans_category($category, $field = 'name', $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        $key = is_object($category) ? $category->id : $category;
        return Translation::getTranslated($locale, 'categories', $key . '_' . $field, $default);
    }
}
if (!function_exists('trans_store')) {
    /**
     * Translate store content
     */
    function trans_store($store, $field = 'name', $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        $key = is_object($store) ? $store->id : $store;
        return Translation::getTranslated($locale, 'stores', $key . '_' . $field, $default);
    }
}

if (!function_exists('trans_page')) {
    /**
     * Translate store content
     */
    function trans_page($page, $field = 'name', $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        $key = is_object($page) ? $page->id : $page;
        return Translation::getTranslated($locale, 'pages', $key . '_' . $field, $default);
    }
}

if (!function_exists('trans_coupon')) {
    /**
     * Translate store content
     */
    function trans_coupon($coupon, $field = 'name', $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        $key = is_object($coupon) ? $coupon->id : $coupon;
        return Translation::getTranslated($locale, 'coupons', $key . '_' . $field, $default);
    }
}

if (!function_exists('trans_content')) {
    /**
     * Translate store content
     */
    function trans_content($content, $field = 'name', $default = null, $locale = null)
    {
        $locale = $locale ?: app()->getLocale();
        $key = is_object($content) ? $content->id : $content;
        return Translation::getTranslated($locale, 'sitecontent', $key . '_' . $field, $default);
    }
}