<?php //composer autoloader include '../vendor/autoload.php'; use Smarty; $lang = isset($_GET['lang']) ? $_GET['lang'] : 'bg'; $file_to_translate = 'smarty.html'; $file_with_translations = 'locale/' . $lang . '/' . $file_to_translate . '.php'; Gettext\Translator::loadTranslations($file_with_translations); $smarty = new Smarty(); //$smarty->setTemplateDir("View"); $smarty->setCompileDir("templates_c"); $smarty->setCacheDir("cache"); //$smarty->setConfigDir(APPPATH."config/smarty"); //register $smarty->registerPlugin("function", "__", 'smarty__'); $smarty->registerPlugin("function", "__n", 'smartyn__'); $smarty->registerPlugin("function", "__p", 'smartyp__'); $smarty->registerPlugin("function", "__np", 'smartynp__'); function smarty__($params) { $original = $params['original']; return __($original); } function smartyn__($params) { $original = $params['original']; $plural = $params['plural']; $n = $params['count']; return n__($original, $plural, $n); }
/** * @depends testPoFileExtractor */ public function testMultiPlural($translations) { $translator = new \Gettext\Translator(); $translator->loadTranslations($translations); //Set the current translator before execute the functions __currentTranslator($translator); /** * Test that nplural=3 plural translation check comes up with the correct translation key. */ $this->assertEquals('1 plik', n__("one file", "multiple files", 1), "plural calculation result bad"); $this->assertEquals('2,3,4 pliki', n__("one file", "multiple files", 2), "plural calculation result bad"); $this->assertEquals('2,3,4 pliki', n__("one file", "multiple files", 3), "plural calculation result bad"); $this->assertEquals('2,3,4 pliki', n__("one file", "multiple files", 4), "plural calculation result bad"); $this->assertEquals('5-21 plików', n__("one file", "multiple files", 5), "plural calculation result bad"); $this->assertEquals('5-21 plików', n__("one file", "multiple files", 6), "plural calculation result bad"); /** * Test that when less then the nplural translations are available it still works. */ $this->assertEquals('1', n__("one", "more", 1), "non-plural fallback failed"); $this->assertEquals('*', n__("one", "more", 2), "non-plural fallback failed"); $this->assertEquals('*', n__("one", "more", 3), "non-plural fallback failed"); /** * Test that non-plural translations the fallback still works. */ $this->assertEquals('more', n__("single", "more", 3), "non-plural fallback failed"); }