i18n_path.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) module - Translation set
  5. */
  6. class i18n_path_translation_set extends i18n_translation_set {
  7. /**
  8. * Add translation item
  9. */
  10. public function add_item($path, $langcode = NULL) {
  11. // Path may be object or plain string
  12. $item = is_object($path) ? $path : (object)array('path' => $path, 'language' => $langcode);
  13. return parent::add_item($item, $langcode);
  14. }
  15. /**
  16. * Clean path translations.
  17. *
  18. * Unlike other translation sets this actually deletes paths
  19. */
  20. public function clean_translations() {
  21. $delete = db_delete('i18n_path')
  22. ->condition('tsid', $this->tsid)
  23. ->condition('language', array_keys($this->get_translations()), 'NOT IN')
  24. ->execute();
  25. }
  26. /**
  27. * Delete translation set
  28. */
  29. public function delete_translations() {
  30. return db_delete('i18n_path')
  31. ->condition('tsid', $this->tsid)
  32. ->execute();
  33. }
  34. /**
  35. * Save all path translations
  36. */
  37. public function save_translations() {
  38. foreach ($this->get_translations() as $lang => $path) {
  39. $path = is_object($path) ? $path : (object) array('path' => $path, 'language' => $lang, 'tsid' => $this->tsid);
  40. drupal_write_record('i18n_path', $path, !empty($path->tpid) ? 'tpid' : array());
  41. $this->add_item($path, $lang);
  42. }
  43. }
  44. }
  45. /**
  46. * Path object
  47. */
  48. class i18n_path_object extends i18n_object_wrapper {
  49. /**
  50. * Get title from item
  51. */
  52. public function get_title() {
  53. return $this->object->path;
  54. }
  55. /**
  56. * Get path for item
  57. */
  58. public function get_path() {
  59. return check_url($this->object->path);
  60. }
  61. /**
  62. * Get translate mode
  63. */
  64. public function get_translate_mode() {
  65. return I18N_MODE_TRANSLATE;
  66. }
  67. }