i18n.api.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for Internationalization module
  5. *
  6. * Most i18n hooks can be placed on each module.i18n.inc file but in this case
  7. * such file must be listed in the module.info file.
  8. */
  9. /**
  10. * Provide information about object types handled by i18n system.
  11. *
  12. * @see i18n_object_info()
  13. *
  14. * Other features like translation sets (i18n_translation) or string translation (i18n_string)
  15. * rely on the information provided by this hook for automating string translation
  16. */
  17. function hook_i18n_object_info() {
  18. // Information for node type object, see i18n_node_i18n_object_info()
  19. $info['node_type'] = array(
  20. // Generic object properties, title, etc..
  21. 'title' => t('Node type'),
  22. // Field to be used as key to index different node types
  23. 'key' => 'type',
  24. // Mapping object fields and menu place holders
  25. 'placeholders' => array(
  26. '%node_type' => 'type',
  27. ),
  28. // Path for automatically generated translation tabs. Note placeholders above are used here.
  29. 'edit path' => 'admin/structure/types/manage/%node_type',
  30. 'translate tab' => 'admin/structure/types/manage/%node_type/translate',
  31. // We can easily list all these objects because they should be limited and manageable
  32. // Only in this case we provide a 'list callback'.
  33. 'list callback' => 'node_type_get_types',
  34. // Metadata for string translation
  35. // In this case we are defining fields and keys for string translation's string names
  36. // String ids are of the form: [textgroup]:[type]:[key]:[property]
  37. // Thus in this case we'll have string names like
  38. // - node:type:story:name
  39. // - node:type:story:description
  40. 'string translation' => array(
  41. 'textgroup' => 'node',
  42. 'type' => 'type',
  43. 'properties' => array(
  44. 'name' => t('Name'),
  45. 'title_label' => t('Title label'),
  46. 'description' => t('Description'),
  47. 'help' => t('Help text'),
  48. ),
  49. 'translate path' => 'admin/structure/types/manage/%node_type/translate/%i18n_language',
  50. )
  51. );
  52. // Example information for taxonomy term object, see i18n_taxonomy_i18n_object_info().
  53. $info['taxonomy_term'] = array(
  54. 'title' => t('Taxonomy term'),
  55. 'class' => 'i18n_taxonomy_term',
  56. 'entity' => 'taxonomy_term',
  57. 'key' => 'tid',
  58. 'placeholders' => array(
  59. '%taxonomy_term' => 'tid',
  60. ),
  61. // Auto generate edit path
  62. 'edit path' => 'taxonomy/term/%taxonomy_term/edit',
  63. // Auto-generate translate tab
  64. 'translate tab' => 'taxonomy/term/%taxonomy_term/translate',
  65. 'string translation' => array(
  66. 'textgroup' => 'taxonomy',
  67. 'type' => 'term',
  68. 'properties' => array(
  69. 'name' => t('Name'),
  70. 'description' => array(
  71. 'title' => t('Description'),
  72. 'format' => 'format',
  73. ),
  74. ),
  75. )
  76. );
  77. return $info;
  78. }
  79. /**
  80. * Alter i18n object information provided by modules with the previous hook
  81. *
  82. * @see i18n_object_info()
  83. */
  84. function hook_i18n_object_info_alter(&$info) {
  85. }
  86. /**
  87. * Provide information about available translations for specific path.
  88. *
  89. * @see i18n_get_path_translations($path)
  90. *
  91. * @param $path
  92. * Internal path to translate.
  93. * @return array
  94. * Translations indexed by language code. Each translation is an array with:
  95. * - 'path'
  96. * - 'title'
  97. * - 'options'
  98. */
  99. function hook_i18n_translate_path($path) {
  100. if ($path == 'mypath') {
  101. $translations['es'] = array(
  102. 'path' => 'mypath/spanish',
  103. 'title' => t('My Spanish translation'),
  104. );
  105. return $translations;
  106. }
  107. }
  108. /**
  109. * Alter path translations
  110. */
  111. function hook_i18n_translate_path_alter(&$translations, $path) {
  112. }