11<?php
22namespace Gettext ;
33
4- use Gettext \ Translations ;
4+ use Exception ;
55use Gettext \Generators \PhpArray ;
66
77class Translator
@@ -22,13 +22,15 @@ public function loadTranslations($translations)
2222 {
2323 if ($ translations instanceof Translations) {
2424 $ this ->loadArray (PhpArray::toArray ($ translations ));
25- } else if (is_string ($ translations ) && is_file ($ translations )) {
25+ } elseif (is_string ($ translations ) && is_file ($ translations )) {
2626 $ this ->loadArray (include $ translations );
27- } else if (is_array ($ translations )) {
27+ } elseif (is_array ($ translations )) {
2828 $ this ->loadArray ($ translations );
2929 } else {
3030 throw new \InvalidArgumentException ('Invalid Translator: only arrays, files or instance of Translations are allowed ' );
3131 }
32+
33+ return $ this ;
3234 }
3335
3436 /**
@@ -60,7 +62,7 @@ protected function loadArray(array $translations)
6062 * @param array $translations
6163 * @param null|string $domain
6264 */
63- protected function addTranslations (array $ translations , $ domain = null )
65+ public function addTranslations (array $ translations , $ domain = null )
6466 {
6567 if ($ domain === null ) {
6668 $ domain = $ this ->domain ;
@@ -73,6 +75,14 @@ protected function addTranslations(array $translations, $domain = null)
7375 }
7476 }
7577
78+ /**
79+ * Clear all translations
80+ */
81+ public function clearTranslations ()
82+ {
83+ $ this ->dictionary = array ();
84+ }
85+
7686 /**
7787 * Search and returns a translation
7888 *
@@ -82,7 +92,7 @@ protected function addTranslations(array $translations, $domain = null)
8292 *
8393 * @return array
8494 */
85- protected function getTranslation ($ domain , $ context , $ original )
95+ public function getTranslation ($ domain , $ context , $ original )
8696 {
8797 $ key = isset ($ context ) ? $ context .$ this ->context_glue .$ original : $ original ;
8898
@@ -219,7 +229,7 @@ public function dnpgettext($domain, $context, $original, $plural, $value)
219229 * @param string $n
220230 * @return int
221231 */
222- protected function isPlural ($ n )
232+ public function isPlural ($ n )
223233 {
224234 if (!$ this ->pluralFunction ) {
225235 $ this ->pluralFunction = create_function ('$n ' , self ::fixTerseIfs ($ this ->pluralCode ));
0 commit comments