Author: ornicar2
Date: 2010-01-16 18:56:54 +0100 (Sat, 16 Jan 2010)
New Revision: 26730

Added:
   plugins/diemPlugin/trunk/dmCorePlugin/test/unit/dmTransliterationTest.php
Modified:
   plugins/diemPlugin/trunk/dmCorePlugin/lib/basic/dmString.php
   plugins/diemPlugin/trunk/dmCorePlugin/lib/i18n/dmI18n.php
Log:
[Diem]
- moved transliteration strings to the i18n service
- added unit tests for dmString::transliterate

Modified: plugins/diemPlugin/trunk/dmCorePlugin/lib/basic/dmString.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/basic/dmString.php        
2010-01-16 16:48:37 UTC (rev 26729)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/basic/dmString.php        
2010-01-16 17:56:54 UTC (rev 26730)
@@ -153,30 +153,13 @@
       return $text;
     }
     
-    $text = strtr($text, array(
-      '¥' => 'Y', 'µ' => 'u', 'À' => 'A', 'Á' => 'A',
-      'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A',
-      'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
-      'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I',
-      'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N',
-      'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O',
-      'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U',
-      'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'ß' => 'ss',
-      'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a',
-      'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c',
-      'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e',
-      'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
-      'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o',
-      'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o',
-      'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u',
-      'ý' => 'y', 'ÿ' => 'y', 'œ' => 'oe'
-    ));
+    $text = strtr($text, sfConfig::get('dm_string_transliteration'));
+
+//    if (function_exists('iconv'))
+//    {
+//      $text = iconv('UTF-8', 'ASCII//TRANSLIT', $text);
+//    }
     
-    if (function_exists('iconv'))
-    {
-      $text = iconv('UTF-8', 'ASCII//TRANSLIT', $text);
-    }
-    
     return $text;
   }
   

Modified: plugins/diemPlugin/trunk/dmCorePlugin/lib/i18n/dmI18n.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/i18n/dmI18n.php   2010-01-16 
16:48:37 UTC (rev 26729)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/i18n/dmI18n.php   2010-01-16 
17:56:54 UTC (rev 26730)
@@ -143,6 +143,65 @@
     }
   }
 
+  /**
+   * Listens to the user.change_culture event.
+   *
+   * @param sfEvent $event  An sfEvent instance
+   *
+   */
+  public function listenToChangeCultureEvent(sfEvent $event)
+  {
+    parent::listenToChangeCultureEvent($event);
+    
+    $this->loadTransliterationStrings();
+  }
+
+  protected function loadTransliterationStrings()
+  {
+    $transliterationMap = array(
+      '¥' => 'Y', 'µ' => 'u', 'À' => 'A', 'Á' => 'A',
+      'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A',
+      'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
+      'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I',
+      'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N',
+      'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O',
+      'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U',
+      'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'ß' => 'ss',
+      'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a',
+      'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c',
+      'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e',
+      'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
+      'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o',
+      'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o',
+      'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u',
+      'ý' => 'y', 'ÿ' => 'y', 'œ' => 'oe'
+    );
+
+    switch($this->getCulture())
+    {
+      case 'ru':
+        $transliterationMap = array_merge($transliterationMap, array(
+          'Г'=>'G','Ё'=>'YO','Е'=>'E','Й'=>'YI','И'=>'I',
+          'и'=>'i','г'=>'g','ё'=>'yo','№'=>'#','е'=>'e',
+          'й'=>'yi','А'=>'A','Б'=>'B','В'=>'V','Г'=>'G',
+          'Д'=>'D','Е'=>'E','Ж'=>'ZH','З'=>'Z','И'=>'I',
+          'Й'=>'Y','К'=>'K','Л'=>'L','М'=>'M','Н'=>'N',
+          'О'=>'O','П'=>'P','Р'=>'R','С'=>'S','Т'=>'T',
+          'У'=>'U','Ф'=>'F','Х'=>'H','Ц'=>'TS','Ч'=>'CH',
+          'Ш'=>'SH','Щ'=>'SCH','Ъ'=>'','Ы'=>'YI','Ь'=>'',
+          'Э'=>'E','Ю'=>'YU','Я'=>'YA','а'=>'a','б'=>'b',
+          'в'=>'v','г'=>'g','д'=>'d','е'=>'e','ж'=>'zh',
+          'з'=>'z','и'=>'i','й'=>'y','к'=>'k','л'=>'l',
+          'м'=>'m','н'=>'n','о'=>'o','п'=>'p','р'=>'r',
+          'с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'h',
+          'ц'=>'ts','ч'=>'ch','ш'=>'sh','щ'=>'sch','ъ'=>'',
+          'ы'=>'yi','ь'=>'','э'=>'e','ю'=>'yu','я'=>'ya'
+        ));
+    }
+
+    sfConfig::set('dm_string_transliteration', $transliterationMap);
+  }
+
   public function getCultures()
   {
     return $this->cultures;

Added: plugins/diemPlugin/trunk/dmCorePlugin/test/unit/dmTransliterationTest.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/test/unit/dmTransliterationTest.php   
                        (rev 0)
+++ plugins/diemPlugin/trunk/dmCorePlugin/test/unit/dmTransliterationTest.php   
2010-01-16 17:56:54 UTC (rev 26730)
@@ -0,0 +1,48 @@
+<?php
+
+require_once(dirname(__FILE__).'/helper/dmUnitTestHelper.php');
+$helper = new dmUnitTestHelper();
+$helper->boot();
+
+$t = new lime_test(21);
+
+$tests = array(
+  'en' => array(
+    'test' => 'test',
+    'tèst' => 'test',
+    'test...   /[)=' => 'test...   /[)=',
+    'tèst' => 'test',
+    'Í' => 'I',
+    'Î' => 'I',
+    'Ï' => 'I',
+    'Ð' => 'D',
+    'œÐú' => 'oeDu',
+    'ж'=>'ж',
+  ),
+  'ru' => array(
+    'test' => 'test',
+    'tèst' => 'test',
+    'test...   /[)=' => 'test...   /[)=',
+    'tèst' => 'test',
+    'Í' => 'I',
+    'Î' => 'I',
+    'Ï' => 'I',
+    'Ð' => 'D',
+    'œÐú' => 'oeDu',
+    'ж'=>'zh',
+    'з'=>'z',
+    'и'=>'i',
+    'й'=>'y'
+  )
+);
+
+foreach($tests as $culture => $strings)
+{
+  $helper->get('user')->setCulture($culture);
+  $t->comment('Current culture is '.$culture);
+
+  foreach($strings as $source => $target)
+  {
+    $t->is(dmString::transliterate($source), $target, 
'dmString::transliterate("'.$source.'") -> '.$target);
+  }
+}
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to