1: <?php
2:
3: class QI18nTests extends QUnitTestCaseBase {
4: public function testTranslationBasic() {
5: $this->setCustomTranslatorClass();
6:
7: $this->verifyTranslation("Required", QApplication::Translate("Required"), "Requis");
8: $this->verifyTranslation("Hello", QApplication::Translate("Hello"), "Bonjour");
9:
10:
11: $this->verifyTranslation("Can't translate me!", QApplication::Translate("Can't translate me!"), "Can't translate me!");
12: }
13:
14: public function testTranslationLoad() {
15: $this->setCustomTranslatorClass();
16:
17: $translator = QI18n::Load('es');
18:
19: $this->verifyTranslation("Required", $translator->TranslateToken("Required"), "Obligatorio");
20: $this->verifyTranslation("Optional", $translator->TranslateToken("Optional"), "Opcional");
21:
22:
23: $this->verifyTranslation("Can't translate me!", $translator->TranslateToken("Can't translate me!"), "Can't translate me!");
24: }
25:
26: public function testPoParserBasic() {
27: QI18n::$DefaultTranslationClass = 'QTranslationPoParser';
28:
29: $translator = QI18n::Load('es');
30:
31: $this->verifyTranslation("List All", $translator->TranslateToken("List All"), "Mostrar Todos");
32: $this->verifyTranslation("Create a New", $translator->TranslateToken("Create a New"), "Crear uno Nuevo");
33:
34:
35: $this->verifyTranslation("Can't translate me!", $translator->TranslateToken("Can't translate me!"), "Can't translate me!");
36: }
37:
38: private function setCustomTranslatorClass() {
39: require_once (__DOCROOT__ . __EXAMPLES__ . '/communication/sample_translator.class.php');
40:
41: QI18n::$DefaultTranslationClass = 'QSampleTranslation';
42:
43:
44: QApplication::$LanguageCode = 'fr';
45: QApplication::$CountryCode = null;
46: QI18n::Initialize();
47: }
48:
49: private function verifyTranslation($original, $translation, $expectedTranslation) {
50: $this->assertEquals($expectedTranslation, $translation, "'" . $original . "' translates to '" . $translation . "'.");
51: }
52:
53: public function tearDown() {
54:
55: QI18n::$DefaultTranslationClass = 'QTranslationPoParser';
56: }
57: }
58: