SymfonyComponentTranslationDumperIcuResFileDumper

IcuResDumper generates an ICU ResourceBundle formatted string representation of a message catalogue.

Defined (1)

The class is defined in the following location(s).

/vendor/symfony/translation/Dumper/IcuResFileDumper.php  
  1. class IcuResFileDumper extends FileDumper 
  2. /** 
  3. * {@inheritdoc} 
  4. */ 
  5. protected $relativePathTemplate = '%domain%/%locale%.%extension%'; 
  6.  
  7. /** 
  8. * {@inheritdoc} 
  9. */ 
  10. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array()) 
  11. $data = $indexes = $resources = ''; 
  12.  
  13. foreach ($messages->all($domain) as $source => $target) { 
  14. $indexes .= pack('v', strlen($data) + 28); 
  15. $data .= $source."\0"; 
  16.  
  17. $data .= $this->writePadding($data); 
  18.  
  19. $keyTop = $this->getPosition($data); 
  20.  
  21. foreach ($messages->all($domain) as $source => $target) { 
  22. $resources .= pack('V', $this->getPosition($data)); 
  23.  
  24. $data .= pack('V', strlen($target)) 
  25. .mb_convert_encoding($target."\0", 'UTF-16LE', 'UTF-8') 
  26. .$this->writePadding($data) 
  27.  
  28. $resOffset = $this->getPosition($data); 
  29.  
  30. $data .= pack('v', count($messages)) 
  31. .$indexes 
  32. .$this->writePadding($data) 
  33. .$resources 
  34.  
  35. $bundleTop = $this->getPosition($data); 
  36.  
  37. $root = pack('V7',  
  38. $resOffset + (2 << 28), // Resource Offset + Resource Type 
  39. 6, // Index length 
  40. $keyTop, // Index keys top 
  41. $bundleTop, // Index resources top 
  42. $bundleTop, // Index bundle top 
  43. count($messages), // Index max table length 
  44. 0 // Index attributes 
  45. ); 
  46.  
  47. $header = pack('vC2v4C12@32',  
  48. 32, // Header size 
  49. 0xDA, 0x27, // Magic number 1 and 2 
  50. 20, 0, 0, 2, // Rest of the header, ..., Size of a char 
  51. 0x52, 0x65, 0x73, 0x42, // Data format identifier 
  52. 1, 2, 0, 0, // Data version 
  53. 1, 4, 0, 0 // Unicode version 
  54. ); 
  55.  
  56. return $header.$root.$data; 
  57.  
  58. private function writePadding($data) 
  59. $padding = strlen($data) % 4; 
  60.  
  61. if ($padding) { 
  62. return str_repeat("\xAA", 4 - $padding); 
  63.  
  64. private function getPosition($data) 
  65. return (strlen($data) + 28) / 4; 
  66.  
  67. /** 
  68. * {@inheritdoc} 
  69. */ 
  70. protected function getExtension() 
  71. return 'res';