*/ /** * Configuration * ------------------------------------------------- */ // BaseTool & Localization require_once __DIR__ . '/../libs/basetool/InitTool.php'; require_once __DIR__ . '/../ToolStart.php'; $I18N = new Intuition(array('domain' => 'tsintuition', 'mode' => 'dashboard')); // Load all domains so we can get some statistics later on and // make sure "getAvailableLangs" is complete foreach ($I18N->getAllRegisteredDomains() as $domainKey) { $I18N->loadTextdomain($domainKey); } // Initialize BaseTool $Tool = BaseTool::newFromArray(array('displayTitle' => $I18N->msg('title'), 'remoteBasePath' => $I18N->dashboardHome, 'localBasePath' => $I18N->localBaseDir, 'revisionId' => $I18N->version, 'styles' => array('main.css'), 'scripts' => array('main.js'), 'licenses' => array('CC-BY 3.0' => 'https://creativecommons.org/licenses/by/3.0/'))); $Tool->setSourceInfoGithub('Krinkle', 'intuition', dirname(__DIR__)); /** * Tool settings * ------------------------------------------------- */ $toolSettings = array('tabs' => array()); /** * Post actions * ------------------------------------------------- */ if (isset($_POST['action'])) { switch ($_POST['action']) { case 'prefset': // Set a 30-day, then redirect to index $I18N->setCookie('userlang', $_POST['fpLang']);
<?php /* Config */ require_once 'demoBase.php'; /* Demonstration */ // 1) Init $options = array('domain' => 'tsintuition', 'suppressnotice' => false); $I18N = new Intuition($options); // 2) Request an undefined message // Because 'suppressnotices' is false, // this will trigger a Notice: 'r4nd0mstr1n9' undefined echo $I18N->msg('r4nd0mstr1n9'); /* View source */ closeDemo(__FILE__);
/** * @covers Intuition::msg * @covers Intuition::bracketMsg */ public function testOptionSuppressbrackets() { $i18n = new Intuition(array('suppressnotice' => true, 'suppressbrackets' => true)); $this->assertEquals('R4nd0mstr1n9', $i18n->msg('r4nd0mstr1n9'), 'Unknown key falls back to ucfirst key'); }
<?php /* Config */ require_once 'demoBase.php'; /* Demonstration */ // 1) Init $I18N = new Intuition('general'); // 2) Register some interesting messages $I18N->setMsgs(array('welcomeback' => 'Welcome back, $1! Would you like some $2?', 'basket' => 'The basket contains $1 {{PLURAL:$1|apple|apples}}.')); // 2) Use rendering and formatting // - Raw echo echo $I18N->msg('apple-stats'); echo '<br/>'; // - Pass variables echo '<br/>' . $I18N->msg('welcomeback', array('variables' => array('John', 'coffee'))); // - Pass variables echo '<br/>' . $I18N->msg('welcomeback', array('variables' => array('George', 'tea'))); echo '<br/>'; // - Trigger parser magic, setting $1 to '1' echo '<br/>' . $I18N->msg('basket', array('variables' => array('1'), 'parsemag' => true)); // - Trigger parser magic, setting $1 to '7' echo '<br/>' . $I18N->msg('basket', array('variables' => array('7'), 'parsemag' => true)); /* View source */ closeDemo(__FILE__);
<?php /* Config */ require_once 'demoBase.php'; /* Demonstration */ // 1) Init $I18N = new Intuition('general'); // 2) Do it // Simple parentheses echo $I18N->parentheses('hello'); // Variables echo '<br/>' . $I18N->msg('toolversionstamp', array('variables' => array('1.0', $I18N->dateFormatted('2001-01-15')))); // msgExists echo '<br/>msgExists: '; var_dump($I18N->msgExists('welcome')); var_dump($I18N->msgExists('foobar')); // nonEmptyStr echo '<br/>nonEmptyStr: '; var_dump(IntuitionUtil::nonEmptyStr('one')); // nonEmptyStrs echo '<br/>nonEmptyStrs: '; var_dump(IntuitionUtil::nonEmptyStrs('one', '', 'three')); var_dump(IntuitionUtil::nonEmptyStrs('one', 'three')); // GetAcceptableLanguages $acceptLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; echo "<br/>getAcceptableLanguages: (default: \$_SERVER['HTTP_ACCEPT_LANGUAGE']: " . htmlspecialchars($acceptLang) . "):<br/>"; var_dump(IntuitionUtil::getAcceptableLanguages($acceptLang)); $acceptLang = 'nl-be,nl;q=0.7,en-us,en;q=0.3'; echo "<br/>getAcceptableLanguages: ( '{$acceptLang}' ):<br/>"; var_dump(IntuitionUtil::getAcceptableLanguages($acceptLang)); /* View source */
<span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand">ra·un<span id="stat"></span></a> </div> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li> <?php // Help ?> <a href="#help" data-toggle="modal" data-target="#help"> <span class="glyphicon glyphicon-question-sign"></span> <?php echo $I18N->msg('help'); ?> </a> </li> <li class="dropdown"> <?php // Filter ?> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span class="glyphicon glyphicon-filter"></span> <?php echo $I18N->msg('filter'); ?> <b class="caret"></b> </a>
<?php /* Config */ require_once 'demoBase.php'; /* Demonstration */ // 1) Init $I18N $I18N = new Intuition('general'); // 2) Get message echo $I18N->msg('welcome'); /* View source */ closeDemo(__FILE__);
<?php /* Config */ require_once 'demoBase.php'; /* Demonstration */ // 1) Init $I18N $I18N = new Intuition('demo'); $I18N->registerDomain('demo', __DIR__ . '/messages/demo'); // 2) Get message echo $I18N->msg('example'); /* View source */ closeDemo(__FILE__);
<?php /* Config */ require_once 'demoBase.php'; /* Demonstration */ // Because 'suppressnotices' is true (default), this won't trigger a notice. $I18N = new Intuition(array('domain' => 'demo')); echo $I18N->msg('foo') . '<br/>'; // Because 'suppressnotices' is false, this will trigger a "Notice: 'bar' undefined" $I18N = new Intuition(array('domain' => 'demo', 'suppressnotice' => false)); echo $I18N->msg('bar') . '<br/>'; // Because 'suppressbrackets' is true, gthis will display "Quux" instead of "[quux]" $I18N = new Intuition(array('domain' => 'demo', 'suppressbrackets' => true)); echo $I18N->msg('quux') . '<br/>'; /* View source */ closeDemo(__FILE__);
public function testOptionShowNotices() { $i18n = new Intuition(array('suppressnotice' => false)); $this->assertEquals('[r4nd0mstr1n9]', $i18n->msg('r4nd0mstr1n9'), 'Unknown key falls back to bracket-wrapped key'); $this->expectOutputString('Notice: [Intuition::msg] Message "r4nd0mstr1n9" in domain "general" not found.'); }