1. Vladimir Mihailenco
  2. vladimir.webdev

Commits

root <>  committed a5c3e6e

Introduce ZendY_Translate

  • Participants
  • Parent commits 271ecd2
  • Branches default

Comments (0)

Files changed (1)

File library/ZendY/Translate.php

View file
  • Ignore whitespace
+<?php
+class ZendY_Translate extends Zend_Translate
+{
+    private static $_fallbackLocales = array();
+
+    public static function setFallbackLocales(array $value)
+    {
+        self::$_fallbackLocales = $value;
+    }
+
+    public static function getFallbackLocales()
+    {
+        return self::$_fallbackLocales;
+    }
+
+    public function getAdapter()
+    {
+        return $this;
+    }
+
+    public function translate($messageId, $locale = null)
+    {
+        $adapter = parent::getAdapter();
+        $locales = array_merge(array($locale), self::$_fallbackLocales);
+        foreach ($locales as $currentLocale) {
+            if ($adapter->isTranslated($messageId, false, $currentLocale)) {
+                return $adapter->translate($messageId, $currentLocale);
+            }
+        }
+
+        return $adapter->translate($messageId, $locale);
+    }
+}