dp-mis/ci4extension

Dediprog MIS Codeigniter 4 Extension

1.2.0 2025-05-12 11:32 UTC

This package is not auto-updated.

Last update: 2025-06-23 04:11:11 UTC


README

i18n config template

<?php
$i18n_config = [
    "frontend" => [
        "google_sheet_id" => "1yOAWR89Okm4y1-wDEpnRREbQDjvhGWuxNQRlRdRXkcY",
        "language_map" => [ // google sheet column index
            // 0 = A, 1 = B, 2 = C, 3 = D, 4 = E
            "en" => 1,
            "zh-tw" => 2,
            "zh-cn" => 3,
            "ja" => 4,
            "es" => 5,
        ],
        "prefix_config" => [
            "php" => [ // php prefix sheet name, eg : php_common
                "formatter" => "php",
                "path" => "app/Language/{lang}/frontend/", // {lang} will be replaced with the language code
                // eg : app/Language/en/frontend/
                // all path are relative to the project root
                "sheet_has_header" => true,
                // this config will remove first line (Default: False)
            ],
            "js" => [ // js prefix sheet name, eg : js_common
                "formatter" => "json",
                "path" => "public/assets/i18n/frontend/{lang}/",
            ],
        ],
    ],
    "cpanel" => [
        "google_sheet_id" => "17ybM3LyPiyDRrUcF0UkezLLysq3gFz4xbl1Ua7HufhI",
        "language_map" => [
            "en" => 1,
            "zh-tw" => 2,
            "zh-cn" => 3,
            "ja" => 4,
            "es" => 5,
        ],
        "prefix_config" => [
            "php" => [
                "formatter" => "php",
                "path" => "app/Language/{lang}/cpanel/",
            ],
            "js" => [
                "formatter" => "json",
                "path" => "public/assets/i18n/cpanel/{lang}/",
            ],
        ],
    ],
    "i18n" => [
        "google_sheet_id" => "1RdHM12MkNEFTnSPOydXa5SACp_ez0WruCVxKtu2kV80",
        "language_map" => [
            "en" => 1,
            "zh-tw" => 2,
            "zh-cn" => 3,
            "ja" => 4,
            "es" => 5,
        ],
        "prefix_config" => [
            "php" => [
                "formatter" => "php",
                "path" => "app/Language/{lang}/",
            ],
            "js" => [
                "formatter" => "json",
                "path" => "public/assets/i18n/{lang}/",
            ],
        ],
    ],
];

use DpMIS\Ci4extension\I18n\I18nHelper;
$google_service_key_path = ""path/to/google_service_key.json";
$i18nHelper = new I18nHelper($google_service_key_path);
try {
    $i18nHelper->setConfig($i18n_config[$target])->fromGoogle();
} catch (\Exception $e) {
    echo "Error stack : " . $e->getTraceAsString();
    echo "Error : " . $e->getMessage();
    return;
}