Example #1
0
<?php

/* Config */
require_once 'demoBase.php';
$I18N = new Intuition('general');
/* Demonstration */
echo $I18N->dashboardBacklink();
echo $I18N->getPromoBox();
echo $I18N->getFooterLine();
// defaults to TSINT_HELP_CURRENT
echo $I18N->getFooterLine('orphantalk2');
echo $I18N->getFooterLine(TSINT_HELP_NONE);
echo $I18N->getFooterLine(TSINT_HELP_ALL);
/* View source */
closeDemo(__FILE__);
Example #2
0
 function initI18N()
 {
     global $redis;
     $ttl = 86400;
     $hash = "xtoolsI18N_" . XTOOLS_REDIS_FLUSH_TOKEN . '35';
     $lc = $redis->get($hash);
     if ($lc === false) {
         $initOpts = array('suppressfatal' => true, 'stayalive' => true);
         $I18N = new Intuition($initOpts);
         $I18N->loadTextdomainFromFile(XTOOLS_I18_TEXTFILE, 'xtools');
         $I18N->setDomain('xtools');
         $redis->setex($hash, $ttl, serialize($I18N));
     } else {
         $I18N = unserialize($lc);
         unset($lc);
     }
     //temp messages
     $this->i18Langs = $I18N->getAvailableLangs('xtools');
     return $I18N;
 }
Example #3
0
<?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__);
Example #4
0
<?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 */
Example #5
0
 /**
  * Get fallback chain for a given language.
  *
  * @param string $lang Language code
  * @return string[] List of one or more language codes
  */
 public function getLangFallbacks($lang)
 {
     if (self::$fallbackCache === null) {
         // Lazy-initialize
         self::$fallbackCache = $this->fetchLangFallbacks();
     }
     $lang = $this->normalizeLang($lang);
     return isset(self::$fallbackCache[$lang]) ? self::$fallbackCache[$lang] : array('en');
 }
Example #6
0
 *
 * @copyright 2011-2014 See AUTHORS.txt
 * @license CC-BY 3.0 <https://creativecommons.org/licenses/by/3.0/>
 * @package intuition
 */
/**
 * Set up
 * -------------------------------------------------
 */
// Load BaseTool
$initPath = dirname(__DIR__) . '/libs/basetool';
require_once $initPath . '/InitTool.php';
// Load Intuition
require_once dirname(__DIR__) . '/ToolStart.php';
// Initialize Intuition
$I18N = new Intuition(array('domain' => 'TsIntuition', 'mode' => 'dashboard'));
/**
 * Request
 * -------------------------------------------------
 */
function i18nApiResp($data)
{
    global $kgReq;
    $callback = $kgReq->getVal('callback');
    // Allow CORS (to avoid having to use JSON-P with cache busting callback)
    $kgReq->setHeader('Access-Control-Allow-Origin', '*');
    // We don't yet support retrieval of when the localisation was last updated,
    // so default to unconditionally caching for 5 minutes.
    $maxAge = 5 * 60;
    $kgReq->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT');
    $kgReq->setHeader('Cache-Control', 'public, max-age=' . intval($maxAge));
Example #7
0
<?php

/* Config */
require_once 'demoBase.php';
/* Demonstration */
// 1) Init $I18N
$I18N = new Intuition('general');
// 2) Get domain info (eg. url)
var_dump($I18N->getDomainInfo('tsintuition'));
/* View source */
closeDemo(__FILE__);
Example #8
0
<?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__);
Example #9
0
 * @author Kenrick <*****@*****.**>
 * @license MIT License <http://opensource.org/licenses/MIT>
 */
ob_start();
$locale = "";
$language = "";
$project = "";
$locale_force_get = false;
$language_force_get = false;
$project_force_get = false;
$title_info = "";
// [Need Krinkle/inuition to run: Remember to change it to correct path]
$IntuitionStartFile = __DIR__ . '/vendor/autoload.php';
// Intuition initialization
require_once $IntuitionStartFile;
$I18N = new Intuition(array('domain' => 'raun', 'suppressbrackets' => true));
$locale = $I18N->getLang();
if (isset($_GET['userlang'])) {
    $locale_force_get = true;
}
// Decide language (of the project)
if (isset($_GET['language'])) {
    $language_force_get = true;
    $language = htmlspecialchars($_GET['language']);
} else {
    $language = "id";
}
// Decide the project
if (isset($_GET['project'])) {
    $project_force_get = true;
    $project = htmlspecialchars($_GET['project']);
Example #10
0
<?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__);
Example #11
0
<?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__);
Example #12
0
<?php

/**
 * Extract language data from MediaWiki core.
 *
 * @copyright 2011-2015 See AUTHORS.txt
 * @license CC-BY 3.0 <https://creativecommons.org/licenses/by/3.0/>
 * @package intuition
 */
$dest = dirname(__DIR__) . '/language';
if (!is_writable($dest)) {
    echo "error: Unable to write to {$dest}\n";
    exit(1);
}
require_once __DIR__ . '/../vendor/autoload.php';
$intuition = new Intuition('general');
$data = $intuition->generateLanguageList();
$code = '<?php return ' . var_export($data, true) . ';';
$destFile = "{$dest}/langlist.php";
$written = file_put_contents($destFile, $code);
if (!$written) {
    echo "error: Failed to write {$destFile}\n";
    exit(1);
}
Example #13
0
<?php

/* Config */
require_once 'demoBase.php';
/* Demonstration */
// 1) Init
$I18N = new Intuition('general');
// 2) Use language names
// - Current language name
echo $I18N->getLangName();
// - Specific language name
echo '<br/>' . $I18N->getLangName('fr');
/* View source */
closeDemo(__FILE__);
Example #14
0
 *
 * @copyright 2011-2014 See AUTHORS.txt
 * @license CC-BY 3.0 <https://creativecommons.org/licenses/by/3.0/>
 * @package intuition
 */
/**
 * Set up
 * -------------------------------------------------
 */
// Load BaseTool
$initPath = dirname(__DIR__) . '/libs/basetool';
require_once $initPath . '/InitTool.php';
// Load Intuition
require_once dirname(__DIR__) . '/ToolStart.php';
// Initialize Intuition
$I18N = new Intuition(array('domain' => 'TsIntuition', 'mode' => 'dashboard'));
/**
 * Request
 * -------------------------------------------------
 */
function i18nApiResp($data)
{
    global $kgReq;
    $callback = $kgReq->getVal('callback');
    // Serve as JSON or JSON-P
    if ($callback === null) {
        header('content-type: application/json; charset=utf-8', true);
        echo json_encode($data);
    } else {
        header('content-type: text/javascript; charset=utf-8', true);
        // Sanatize callback
Example #15
0
 /**
  * @covers Intuition::getLangFallbacks
  * @covers Intuition::fetchLangFallbacks
  */
 public function testLangFallback()
 {
     // Ensure fetchLangFallbacks is tested
     Intuition::clearCache();
     $fallbacks = $this->i18n->getLangFallbacks('de-formal');
     $this->assertEquals($fallbacks, array('de', 'en'));
 }
Example #16
0
<?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__);
Example #17
0
 * Main entry point (web dashboard).
 *
 * This file outputs the interface to change user preferences.
 *
 * @copyright 2011-2014 See AUTHORS.txt
 * @license CC-BY 3.0 <https://creativecommons.org/licenses/by/3.0/>
 * @package intuition
 */
/**
 * 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
Example #18
0
 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.');
 }