mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-03 17:08:49 -04:00
initial work on translations, covering the PHP side of it
This commit is contained in:
parent
28776ac178
commit
a2af88a36e
10 changed files with 409 additions and 57 deletions
|
@ -3,6 +3,7 @@ error_reporting( E_ALL | E_STRICT );
|
|||
|
||||
// change this, if your php files and data is outside of your webservers document root
|
||||
if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR);
|
||||
if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..');
|
||||
|
||||
require PATH . 'lib/auto.php';
|
||||
|
||||
|
|
41
tst/i18n.php
Normal file
41
tst/i18n.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
class i18nTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $_translations = array();
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
/* Setup Routine */
|
||||
$this->_translations = json_decode(
|
||||
file_get_contents(PATH . 'i18n' . DIRECTORY_SEPARATOR . 'de.json'),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
/* Tear Down Routine */
|
||||
}
|
||||
|
||||
public function testTranslationFallback()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar';
|
||||
$messageId = 'It does not matter if the message ID exists';
|
||||
i18n::loadTranslations();
|
||||
$this->assertEquals($messageId, i18n::_($messageId), 'fallback to en');
|
||||
}
|
||||
|
||||
public function testBrowserLanguageDetection()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-CH,de;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
|
||||
i18n::loadTranslations();
|
||||
$this->assertEquals($this->_translations['en'], i18n::_('en'), 'browser language de');
|
||||
}
|
||||
|
||||
public function testVariableInjection()
|
||||
{
|
||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar';
|
||||
i18n::loadTranslations();
|
||||
$this->assertEquals('some string + 1', i18n::_('some %s + %d', 'string', 1), 'browser language de');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue