i18n_menu.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) module - Translation set
  5. */
  6. class i18n_menu_link_translation_set extends i18n_translation_set {
  7. /**
  8. * Load all path translations
  9. */
  10. public function load_translations() {
  11. $translations = array();
  12. $query = db_select('menu_links', 'ml');
  13. $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
  14. $query->fields('ml');
  15. // Weight should be taken from {menu_links}, not {menu_router}.
  16. $query->addField('ml', 'weight', 'link_weight');
  17. $query->fields('m');
  18. $query->condition('ml.i18n_tsid', $this->tsid);
  19. foreach ($query->execute()->fetchAll(PDO::FETCH_ASSOC) as $item) {
  20. $item['weight'] = $item['link_weight'];
  21. _menu_link_translate($item);
  22. $translations[$item['language']] = $item;
  23. }
  24. return $translations;
  25. }
  26. }
  27. /**
  28. * Menu link object
  29. */
  30. class i18n_menu_link extends i18n_string_object_wrapper {
  31. /**
  32. * Class constructor
  33. */
  34. public function __construct($type, $key, $object) {
  35. // Unserialize options if not done
  36. if (isset($object['options']) && !is_array($object['options'])) {
  37. $object['options'] = unserialize($object['options']);
  38. }
  39. parent::__construct($type, $key, $object);
  40. }
  41. /**
  42. * Get path for item
  43. */
  44. public function get_path() {
  45. return $this->object['link_path'];
  46. }
  47. /**
  48. * Get title from item
  49. */
  50. public function get_title() {
  51. return $this->object['title'];
  52. }
  53. /**
  54. * Translation mode for object
  55. */
  56. public function get_translate_mode() {
  57. $mode = i18n_menu_mode($this->object['menu_name']);
  58. if ($this->get_langcode()) {
  59. return $mode & I18N_MODE_TRANSLATE;
  60. }
  61. elseif (!empty($this->object['customized'])) {
  62. return $mode & I18N_MODE_LOCALIZE;
  63. }
  64. else {
  65. return I18N_MODE_NONE;
  66. }
  67. }
  68. /**
  69. * Access to object translation. This should check object properties and permissions
  70. */
  71. protected function translate_access() {
  72. return user_access('administer menu') && user_access('translate interface');
  73. }
  74. /**
  75. * Get translatable properties.
  76. *
  77. * Check whether title or description are to be translated by default menu
  78. * system.
  79. */
  80. protected function build_properties() {
  81. $properties = parent::build_properties();
  82. if ($properties) {
  83. $strings = &$properties['menu']['item'][$this->get_key()];
  84. $localizable = _i18n_menu_link_localizable_properties($this->object);
  85. foreach ($strings as $key => $data) {
  86. if (!in_array($key, $localizable)) {
  87. unset($strings[$key]);
  88. }
  89. }
  90. }
  91. return $properties;
  92. }
  93. }