PHP code example of krisanalfa / bono-lang

1. Go to this page and download the library: Download krisanalfa/bono-lang 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/ */

    

krisanalfa / bono-lang example snippets

lang-php
'bono.providers' => array(
    '\\Bono\\Lang\\Provider\\LangProvider',
),
lang-php
'bono.providers' => array(
    '\\Bono\\Lang\\Provider\\LangProvider' => array(
        'driver' => '\\Bono\\Lang\\Driver\\FileDriver',
        'lang'   => 'en',
        'debug'  => true
    ),
),
lang-php
array(
    'driver' => '\\Bono\\Lang\\Driver\\FileDriver',
    'lang' => function() {
        return $_SESSION['user']['config']['lang'];
    },
    'debug' => true
),
lang-php
'bono.providers' => array(
    '\\Bono\\Lang\\Provider\\LangProvider' => array(
        'driver'    => '\\Bono\\Lang\\Driver\\FileDriver',
        'lang'      => 'en',
        'debug'     => true,
        'lang.path' => 'lang'
    ),
),

{{ ROOT }}
├── composer.json
└── lang
    ├── en
    │   └── list.php
    │   └── anotherList.php
    └── id
        └── list.php
        └── extraList.php

{{ ROOT }}
├── composer.json
└── lang
    ├── en
    │   └── list.php
    │   └── anotherList.php
    ├── id
    │   └── list.php
    │   └── extraList.php
    └── es
        └── list.php
        └── spanishList.php
lang-php
return array(
    'full_name'  => 'Full Name',
    'birth_date' => 'Birth Date',
    'message'    => 'Hello',
    'flash'      => array(
        'fail'    => 'Sorry, app is currently fucked up', // nested content
        'success' => 'Hurray, that is that I am talking about', // yet another nested content
    ),
);
lang-php
return array(
    'full_name'  => 'Full Name',
    'birth_date' => 'Birth Date',
    'message'    => 'Hello',
    'flash'      => array(
        'fail'    => 'Sorry, app is currently fucked up', // nested content
        'success' => 'Hurray, that is that I am talking about', // yet another nested content
    ),
);
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->translate('message');
echo $word; // output => 'Hello'
lang-php
$word = t('message'); // 't' is an alias for 'translate' method in $translator
echo $word; // output => 'Hello'
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->translate('message', array('name' => 'Alfa'));
echo $word; // output => 'Hello, Alfa'
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->translate('n00p', array(), 'Default one');
echo $word; // output => 'Default one.'
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$flash      = $translator->translate('flash.fail');
echo $flash; // output => 'Sorry, app is currently fucked up'
lang-php
// List of English dictionary
array(
    // ... snip
    'options' => 'Sagara|Xinix|Solusitama',
    // ... snip
);
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->choice('options', 1);
echo $word; // output => 'Sagara'
lang-php
// List of English dictionary
array(
    // ... snip
    'options' => 'Sagara|Xinix :string|Solusitama',
    // ... snip
);
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->choice('options', 2, array('string' => 'Technology'));
echo $word; // output => 'Xinix Technology'
lang-php
// List of English dictionary
array(
    // ... snip
    'options' => 'Sagara|Xinix :string|Solusitama :count',
    // ... snip
);
lang-php
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->choice('options', 3);
echo $word; // output => 'Solusitama 3'