PHP code example of alnaggar / mujam

1. Go to this page and download the library: Download alnaggar/mujam library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alnaggar / mujam example snippets


$welcomeMessage = Mujam::store('php')->get(
    key: 'messages.welcome', 
    locale: 'en',
    fallback: true
);

$storeTranslations = Mujam::store('json')->getAll(
    locale: 'en',
    fallback: true
);

$storeTranslations = Mujam::store('php')->getAll(
    group: 'messages',
    namespace: '*',
    locale: 'en',
    fallback: true
);

Mujam::store('json')->add(
    translations: ['Welcome to Mujam!' => 'Welcome to Mujam!'], 
    locale: 'en'
);

Mujam::store('php')->add(
    translations: ['welcome' => 'Welcome to Mujam!'], 
    group: 'messages', 
    namespace: '*', 
    locale: 'en'
);

Mujam::store('json')->update(
    translations: ['Welcome to Mujam!' => 'Welcome to the Translation Manager!'], 
    locale: 'en'
);

Mujam::store('php')->update(
    translations: ['welcome' => 'Welcome to the Translation Manager!'], 
    group: 'messages', 
    namespace: '*', 
    locale: 'en'
);

Mujam::store('json')->remove(
    keys: ['Welcome to Mujam!'], 
    locale: 'en'
);

Mujam::store('php')->remove(
    items: ['welcome'], 
    group: 'messages', 
    namespace: '*', 
    locale: 'en'
);

Mujam::store('json')->flush(locale: '*');

Mujam::store('php')->flush(
    group: '*', 
    namespace: null, 
    locale: '*'
);

if (Mujam::store('php')->has(
    key: 'messages.welcome', 
    locale: 'en'
)) {
    // Translation exists
}

$storeLocales = Mujam::store('json')->getLocales();

// Retrieves the store structure as an associative array with namespaces as the top-level keys, locales as the second-level keys, and groups as the third-level values.
$storeStructure = Mujam::store('php')->getStructure();

// Fetches the translation from the enabled stores.
$welcomeMessage = __('messages.welcome');

// Package translations continue to work as expected.
$packageTranslation = __('packageNamespace::group.item');

// Inside AppServiceProvider

public function boot()
{
    Mujam::extend(
        driver: 'customDriverName',
        resolver: function ($app, $config) {
            // return the custom store instance.
        }
    );
}

'stores' => [
    'php' => [
        'driver' => 'php',
        'path' => lang_path(),
        'cache' => [
            'enabled' => true,
            'store' => null, // Use application's default cache store
            'prefix' => 'mujam.php',
            'lifetime' => 9999999999, // Forever
        ],
    ],
]
bash
php artisan vendor:publish --tag="mujam-config"