i18n_node.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) module - Node type handling
  5. *
  6. * The i18n strings created by this module are:
  7. * - node:type:[type]:[name,title,body,help]
  8. */
  9. /**
  10. * Implements hook_field_extra_fields().
  11. */
  12. function i18n_node_field_extra_fields() {
  13. $return = array();
  14. $info = entity_get_info('node');
  15. foreach (array_keys($info['bundles']) as $bundle) {
  16. if (i18n_node_type_enabled($bundle)) {
  17. $return['node'][$bundle] = i18n_language_field_extra();
  18. }
  19. }
  20. return $return;
  21. }
  22. /**
  23. * Implements hook_menu().
  24. */
  25. function i18n_node_menu() {
  26. $items['admin/config/regional/i18n/node'] = array(
  27. 'title' => 'Node options',
  28. 'description' => 'Configure extended options for multilingual content and translations.',
  29. 'page callback' => 'drupal_get_form',
  30. 'page arguments' => array('variable_group_form', 'i18n_node'),
  31. 'access arguments' => array('administer site configuration'),
  32. 'type' => MENU_LOCAL_TASK,
  33. 'weight' => 10,
  34. );
  35. $items['i18n/node/autocomplete'] = array(
  36. 'page callback' => 'i18n_node_autocomplete',
  37. 'file' => 'i18n_node.pages.inc',
  38. 'access arguments' => array('administer content translations'),
  39. 'type' => MENU_CALLBACK,
  40. );
  41. return $items;
  42. }
  43. /**
  44. * Implements hook_block_view_MODULE_DELTA_alter().
  45. *
  46. * Set translated help text for node/add pages, replace node_help() text.
  47. */
  48. function i18n_node_block_view_system_help_alter(&$block) {
  49. $arg = drupal_help_arg(arg(NULL));
  50. if ($arg[0] == 'node' && $arg[1] == 'add' && $arg[2]) {
  51. if (($type = node_type_get_type(str_replace('-', '_', $arg[2]))) && !empty($type->help)) {
  52. $help = i18n_node_translate_type($type, 'help', NULL, array('sanitize' => FALSE));
  53. if ($help !== $type->help) {
  54. $block['content'] = str_replace(filter_xss_admin($type->help), filter_xss_admin($help), $block['content']);
  55. }
  56. }
  57. }
  58. elseif ($arg[0] == 'node' && $arg[2] == 'edit') {
  59. $node = menu_get_object();
  60. if ($node && isset($node->type)) {
  61. $type = node_type_get_type($node->type);
  62. $help = i18n_node_translate_type($type, 'help', NULL, array('sanitize' => FALSE));
  63. if ($help !== $type->help) {
  64. $block['content'] = str_replace(filter_xss_admin($type->help), filter_xss_admin($help), $block['content']);
  65. }
  66. }
  67. }
  68. }
  69. /**
  70. * Implements hook_help().
  71. */
  72. function i18n_node_help($path, $arg) {
  73. switch ($path) {
  74. case 'admin/help#i18n_node':
  75. $output = '<p>' . t('Provides some extended multilingual options for nodes.') . '</p>';
  76. $output .= '<p>' . t('Additionally, if <em>String translation</em> enabled, this module will localize all content type configuration texts.') . '</p>';
  77. $output .= '<ul>';
  78. $output .= '<li>' . t('Content type names') . '</li>';
  79. $output .= '<li>' . t('Submission guidelines') . '</li>';
  80. $output .= '<li>' . t("Content type descriptions were previously localized so they won't be affected.") . '</li>';
  81. $output .= '</ul>';
  82. $output .= '<p>' . t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/config/regional/translate'))) . '</p>';
  83. return $output;
  84. case 'admin/config/regional/i18n':
  85. case 'admin/config/regional/i18n/node':
  86. $output = '<p>' . t('You can find some more per content type options on the <a href="@configure_content">Content types administration page</a>.', array('@configure_content' => url('admin/structure/types'))) . '</p>';
  87. return $output;
  88. }
  89. }
  90. /**
  91. * Implements hook_i18n_context_language().
  92. */
  93. function i18n_node_i18n_context_language() {
  94. // Node language when loading specific nodes or creating translations.
  95. if (arg(0) == 'node' ) {
  96. if (($node = menu_get_object('node')) && !empty($node->language) && i18n_node_type_enabled($node)) {
  97. return i18n_language_object($node->language);
  98. }
  99. elseif (arg(1) == 'add' && !empty($_GET['translation']) && !empty($_GET['target']) && ($source = node_load($_GET['translation'])) && i18n_node_type_enabled($source)) {
  100. return i18n_language_object($_GET['target']);
  101. }
  102. }
  103. }
  104. /**
  105. * Implements hook_i18n_translate_path()
  106. */
  107. function i18n_node_i18n_translate_path($path) {
  108. if (preg_match("!^node/(\d+)(/.+|)!", $path, $matches) && ($node = node_load((int) $matches[1])) && i18n_object_langcode($node) && !empty($node->tnid)) {
  109. if ($translations = translation_node_get_translations($node->tnid)) {
  110. $result = array();
  111. foreach ($translations as $langcode => $node_translation) {
  112. $result[$langcode] = array(
  113. 'href' => 'node/' . $node_translation->nid . $matches[2],
  114. 'title' => $node_translation->title,
  115. 'object' => $node_translation,
  116. // Performance: for node view add access information right away.
  117. 'access' => !$matches[2] ? $node_translation->status : NULL,
  118. );
  119. }
  120. return $result;
  121. }
  122. }
  123. }
  124. /**
  125. * Implements hook_menu_alter().
  126. *
  127. * Take over the node translation page.
  128. */
  129. function i18n_node_menu_alter(&$items) {
  130. if (isset($items['node/%node/translate'])) {
  131. $items['node/%node/translate']['page callback'] = 'i18n_node_translation_overview';
  132. $items['node/%node/translate']['file'] = 'i18n_node.pages.inc';
  133. $items['node/%node/translate']['module'] = 'i18n_node';
  134. }
  135. // Take over node/add pages for string translation
  136. $items['node/add']['page callback'] = 'i18n_node_add_page';
  137. $items['node/add']['file'] = 'i18n_node.pages.inc';
  138. $items['node/add']['file path'] = drupal_get_path('module', 'i18n_node');
  139. // @TODO avoid iterating over every router path.
  140. foreach (node_type_get_types() as $type) {
  141. $path = 'node/add/' . str_replace('_', '-', $type->type);
  142. if (isset($items[$path])) {
  143. $items[$path]['title callback'] = 'i18n_node_type_name';
  144. $items[$path]['title arguments'] = array($type->type, $type->name);
  145. }
  146. }
  147. }
  148. /**
  149. * Get node language.
  150. */
  151. function i18n_node_get_lang($nid, $default = '') {
  152. $lang = db_query('SELECT language FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
  153. return $lang ? $lang : $default ;
  154. }
  155. /**
  156. * Get allowed languages for node.
  157. *
  158. * This allows node types to define its own language list implementing hook 'language_list'.
  159. *
  160. * @param $node
  161. * Node to retrieve language list for.
  162. * @param $translate
  163. * Only languages available for translation.
  164. * @param $select
  165. * Only languages that can be selected for this node
  166. */
  167. function i18n_node_language_list($node, $translate = FALSE, $select = FALSE) {
  168. // Check if the node module manages its own language list.
  169. $languages = node_invoke($node, 'language_list', $translate);
  170. if (!$languages) {
  171. $languages = i18n_language_list('name', i18n_node_language_mode($node));
  172. if ($translate && isset($node->tnid) && $node->tnid && ($translations = translation_node_get_translations($node->tnid))) {
  173. unset($translations[$node->language]);
  174. foreach (array_keys($translations) as $langcode) {
  175. unset($languages[$langcode]);
  176. }
  177. }
  178. // Language may be locked for this node type, restrict options to current one
  179. if ($select && i18n_node_language_options($node, 'lock') && !empty($node->language) && !empty($languages[$node->language])) {
  180. $languages = array($node->language => $languages[$node->language]);
  181. }
  182. // Check language required for this type (no language neutral)
  183. elseif (!i18n_node_language_options($node, 'required')) {
  184. $languages = array(LANGUAGE_NONE => t('Language neutral')) + $languages;
  185. }
  186. }
  187. return $languages;
  188. }
  189. /**
  190. * Check options for node language
  191. */
  192. function i18n_node_language_options($node, $option) {
  193. $options = variable_get('i18n_node_options_' . $node->type, array());
  194. return in_array($option, $options, TRUE);
  195. }
  196. /**
  197. * Get language mode for node or node type
  198. */
  199. function i18n_node_language_mode($type) {
  200. $type = is_object($type) ? $type->type : $type;
  201. return variable_get('i18n_node_extended_' . $type, I18N_LANGUAGE_ENABLED);
  202. }
  203. /**
  204. * Implements hook_node_prepare().
  205. */
  206. function i18n_node_node_prepare($node) {
  207. $options = variable_get('i18n_node_options_' . $node->type, array());
  208. if (i18n_node_type_enabled($node) && empty($node->nid) && !i18n_object_langcode($node) && in_array('current', $options)) {
  209. $default = variable_get('i18n_node_default_language_for_' . $node->type, '-- current --');
  210. // Set current language for new nodes if option enabled
  211. if ($default === '-- current --') {
  212. $node->language = i18n_language_content()->language;
  213. }
  214. // If a custom language was specified, apply it.
  215. else {
  216. $node->language = $default;
  217. }
  218. }
  219. }
  220. /**
  221. * Implements hook_permission().
  222. *
  223. * Permissions defined
  224. * - administer all languages
  225. * Disables language conditions for administration pages, so the user can view objects for all languages at the same time.
  226. * This applies for: menu items, taxonomy
  227. * - administer translations
  228. * Will allow to add/remove existing nodes to/from translation sets.
  229. */
  230. function i18n_node_permission() {
  231. return array(
  232. 'administer content translations' => array(
  233. 'title' => t('Administer content translations'),
  234. 'description' => t('Add or remove existing content to translation sets.'),
  235. ),
  236. );
  237. }
  238. /**
  239. * Implements hook_node_view()
  240. */
  241. function i18n_node_node_view($node, $view_mode, $langcode) {
  242. if (i18n_node_type_enabled($node)) {
  243. $extra_fields_display_settings = field_extra_fields_get_display('node', $node->type, $view_mode);
  244. if ($extra_fields_display_settings['language']['visible']) {
  245. $node->content['language'] = array(
  246. '#type' => 'item',
  247. '#title' => t('Language'),
  248. '#markup' => i18n_language_name($node->language),
  249. );
  250. }
  251. }
  252. }
  253. /**
  254. * Implements hook_node_view_alter().
  255. *
  256. * Handles links for extended languages. Sets current interface language.
  257. */
  258. function i18n_node_node_view_alter(&$build) {
  259. if (isset($build['#node'])) {
  260. $node = $build['#node'];
  261. }
  262. // Hide node translation links.
  263. if (variable_get('i18n_hide_translation_links', 0)) {
  264. if (isset($build['links']['translation'])) {
  265. unset($build['links']['translation']);
  266. }
  267. }
  268. elseif (!empty($node->tnid) && !empty($build['links']['translation']) && i18n_node_language_mode($node) == I18N_LANGUAGE_EXTENDED) {
  269. // We only get links for translations for enabled languages
  270. // Set the right languages if language support is extended but not visible.
  271. $links = &$build['links']['translation']['#links'];
  272. $translations = translation_node_get_translations($node->tnid);
  273. foreach (i18n_node_language_list($node) as $langcode => $langname) {
  274. $index = 'translation_' . $langcode;
  275. if ($langcode != $node->language && isset($translations[$langcode]) && $translations[$langcode]->status && !isset($links[$index])) {
  276. // This a published translation to a disabled language. As the node is language extended, display the linkso
  277. // These links shouldn't switch the interface, though they have a language so the right language icon will be added
  278. $language = i18n_language_object($langcode);
  279. $links[$index] = array(
  280. 'href' => 'node/' . $translations[$langcode]->nid,
  281. 'title' => $language->native,
  282. 'language' => $language,
  283. 'attributes' => array(
  284. 'title' => $translations[$langcode]->title,
  285. 'class' => array('translation-link'),
  286. ),
  287. );
  288. }
  289. }
  290. }
  291. }
  292. /**
  293. * Implements hook_node_type_insert()
  294. */
  295. function i18n_node_node_type_insert($info) {
  296. i18n_node_node_type_update($info);
  297. }
  298. /**
  299. * Implements hook_node_type_update()
  300. */
  301. function i18n_node_node_type_update($info) {
  302. if (!empty($info->old_type) && $info->old_type != $info->type) {
  303. i18n_string_update_context("node:type:$info->old_type:*", "node:type:$info->type:*");
  304. }
  305. i18n_string_object_update('node_type', $info);
  306. }
  307. /**
  308. * Implements hook_node_type_delete()
  309. */
  310. function i18n_node_node_type_delete($info) {
  311. i18n_string_object_remove('node_type', $info);
  312. }
  313. /**
  314. * Implements hook_elements().
  315. *
  316. * Add a process callback for textfields.
  317. *
  318. * * @todo Update D7
  319. */
  320. /*
  321. function i18n_node_elements() {
  322. $type = array();
  323. $type['textfield'] = array('#process' => array('i18n_node_textfield_process'));
  324. return $type;
  325. }
  326. */
  327. /**
  328. * Process callback for textfield elements.
  329. *
  330. * When editing or translating a node, set Javascript to rewrite autocomplete
  331. * paths to use the node language prefix rather than the current content one.
  332. *
  333. * @todo Update D7
  334. */
  335. function i18n_node_textfield_process($element) {
  336. global $language;
  337. static $sent = FALSE;
  338. // Ensure we send the Javascript only once.
  339. if (!$sent && isset($element['#autocomplete_path']) && !empty($element['#autocomplete_path']) && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_DEFAULT) != LANGUAGE_NEGOTIATION_DEFAULT) {
  340. // Add a JS file for node forms.
  341. // Determine if we are either editing or translating an existing node.
  342. // We can't act on regular node creation because we don't have a specified
  343. // node language.
  344. $node_edit = $node = menu_get_object() && arg(2) == 'edit' && isset($node->language) && !empty($node->language);
  345. $node_translate = arg(0) == 'node' && arg(1) == 'add' && !empty($_GET['translation']) && !empty($_GET['language']);
  346. if ($node_edit || $node_translate) {
  347. $node_language = $node_edit ? $node->language : $_GET['language'];
  348. // Only needed if the node language is different from the interface one.
  349. if ($node_language != $language->language) {
  350. $languages = language_list();
  351. if (isset($languages[$node_language])) {
  352. drupal_add_js(drupal_get_path('module', 'i18n_node') . '/i18n_node.js');
  353. // Pass the interface and content language base paths.
  354. // Remove any trailing forward slash. Doing so prevents a mismatch
  355. // that occurs when a language has no prefix and hence gets a path
  356. // with a trailing forward slash.
  357. $interface = rtrim(url('', array('absolute' => TRUE)), '/');
  358. $content = rtrim(url('', array('absolute' => TRUE, 'language' => $languages[$node_language])), '/');
  359. $data = array('interface_path' => $interface, 'content_path' => $content);
  360. drupal_add_js(array('i18n' => $data), 'setting');
  361. }
  362. }
  363. }
  364. $sent = TRUE;
  365. }
  366. return $element;
  367. }
  368. /**
  369. * Implements hook_form_FORM_ID_alter().
  370. */
  371. function i18n_node_form_search_form_alter(&$form, &$form_state) {
  372. // Advanced search form. Add language and localize content type names
  373. if ($form['module']['#value'] == 'node' && !empty($form['advanced'])) {
  374. // @todo Handle language search conditions
  375. //$form['advanced']['language'] = _i18n_language_select();
  376. if (!empty($form['advanced']['type'])) {
  377. foreach ($form['advanced']['type']['#options'] as $type => $name) {
  378. $form['advanced']['type']['#options'][$type] = i18n_node_translate_type($type, 'name', $name);
  379. }
  380. }
  381. }
  382. }
  383. /**
  384. * Implements hook_form_FORM_ID_alter().
  385. */
  386. function i18n_node_form_node_type_form_alter(&$form, &$form_state) {
  387. if (isset($form['type'])) {
  388. $disabled = !i18n_node_type_enabled($form['#node_type']);
  389. $form['i18n'] = array(
  390. '#type' => 'fieldset',
  391. '#title' => t('Multilingual settings'),
  392. '#collapsible' => TRUE,
  393. '#collapsed' => TRUE,
  394. '#group' => 'additional_settings',
  395. '#attributes' => array(
  396. 'class' => array('i18n-node-type-settings-form'),
  397. ),
  398. '#description' => t('Extended multilingual options provided by Internationalization module.'),
  399. '#disabled' => $disabled,
  400. );
  401. // Some settings about node languages. Add variables for node type from variable definition
  402. if ($form['#node_type']->type) {
  403. variable_type_include('node_type');
  404. $form['i18n'] += node_variable_type_subform($form['#node_type']->type, array('i18n_node_options', 'i18n_node_default_language_for', 'i18n_node_extended'));
  405. // Only show custom default language field if "current" is checked.
  406. $form['i18n']['i18n_node_default_language_for']['#states'] = array(
  407. 'visible' => array(
  408. ':input[name="i18n_node_options[current]"]' => array('checked' => TRUE),
  409. ),
  410. 'required' => array(
  411. ':input[name="i18n_node_options[current]"]' => array('checked' => TRUE),
  412. ),
  413. );
  414. }
  415. // Add disabled message
  416. if ($disabled) {
  417. $form['i18n']['#description'] .= ' <em>' . t('These will be available only when you enable Multilingual support in Publishing options above.') . '</em>';
  418. foreach (element_children($form['i18n']) as $key) {
  419. $form['i18n'][$key]['#disabled'] = TRUE;
  420. }
  421. }
  422. }
  423. }
  424. /**
  425. * Implements hook_form_BASE_FORM_ID_alter().
  426. */
  427. function i18n_node_form_node_form_alter(&$form, $form_state) {
  428. $node = $form['#node'];
  429. /**
  430. * i18n has to override locale.module
  431. * drupal_alter() fails to order modules correctly in some cases
  432. * for example specific hooks like hook_form_BASE_FORM_ID_alter
  433. *
  434. * its not possbile to reorder hook_form_BASE_FORM_ID_alter with
  435. * hook_module_implements_alter
  436. *
  437. * @see http://drupal.org/node/765860
  438. */
  439. // Replace core's node submit callback with our own,
  440. // in order to translate the node type name.
  441. $key = array_search('node_form_submit', $form['actions']['submit']['#submit']);
  442. if ($key !== FALSE) {
  443. $form['actions']['submit']['#submit'][$key] = 'i18n_node_form_submit';
  444. }
  445. // call a 'private' implemenation of i18n_node_form_node_form_alter()
  446. $form['#after_build'][] = '_i18n_node_form_node_form_alter';
  447. }
  448. /**
  449. * Replacement for core's node_form_submit(), taking care of
  450. * translating node type names.
  451. */
  452. function i18n_node_form_submit($form, &$form_state) {
  453. $node = node_form_submit_build_node($form, $form_state);
  454. $insert = empty($node->nid);
  455. node_save($node);
  456. $node_link = l(t('view'), 'node/' . $node->nid);
  457. $type_name = i18n_node_type_name($node->type);
  458. $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
  459. $t_args = array('@type' => $type_name, '%title' => $node->title);
  460. if ($insert) {
  461. watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
  462. drupal_set_message(t('@type %title has been created.', $t_args));
  463. }
  464. else {
  465. watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
  466. drupal_set_message(t('@type %title has been updated.', $t_args));
  467. }
  468. if ($node->nid) {
  469. $form_state['values']['nid'] = $node->nid;
  470. $form_state['nid'] = $node->nid;
  471. $form_state['redirect'] = node_access('view', $node) ? 'node/' . $node->nid : '<front>';
  472. }
  473. else {
  474. // In the unlikely case something went wrong on save, the node will be
  475. // rebuilt and node form redisplayed the same way as in preview.
  476. drupal_set_message(t('The post could not be saved.'), 'error');
  477. $form_state['rebuild'] = TRUE;
  478. }
  479. // Clear the page and block caches.
  480. cache_clear_all();
  481. }
  482. /**
  483. * Implements hook_form_BASE_FORM_ID_alter().
  484. * Called by i18n_node_form_node_form_alter
  485. */
  486. function _i18n_node_form_node_form_alter($form, &$form_state) {
  487. $node = $form['#node'];
  488. if (i18n_node_type_enabled($node)) {
  489. if (!empty($form['language']['#options'])) {
  490. $form['language']['#options'] = i18n_node_language_list($node, TRUE, TRUE);
  491. }
  492. }
  493. elseif (variable_get('i18n_node_default_language_none', 0) && !isset($form['#node']->nid)) {
  494. // Only do this if the language is really disabled
  495. if (variable_get('language_content_type_' . $node->type, 0) == 0) {
  496. // Override locale module setting default language to nodes. It is already in form_state.
  497. $form['language']['#value'] = $form_state['values']['language'] = LANGUAGE_NONE;
  498. }
  499. }
  500. // Translate field names for title and body for the node edit form.
  501. if (!empty($form['title']['#title'])) {
  502. $form['title']['#title'] = i18n_node_translate_type($node->type, 'title_label', $form['title']['#title']);
  503. }
  504. if (!empty($form['body_field']['body']['#title'])) {
  505. $form['body_field']['body']['#title'] = i18n_node_translate_type($node->type, 'body', $form['body_field']['body']['#title']);
  506. }
  507. // Translate page title for node/add/% and node/%/edit pages.
  508. if (empty($node->nid) && strpos($_GET['q'], 'node/add/' . str_replace('_', '-', $node->type)) === 0) {
  509. drupal_set_title(t('Create @name', array('@name' => i18n_node_type_name($node->type))), PASS_THROUGH);
  510. }
  511. elseif (!empty($node->nid) && $_GET['q'] == 'node/' . $node->nid . '/edit') {
  512. drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => i18n_node_type_name($node->type), '@title' => $node->title)), PASS_THROUGH);
  513. }
  514. return $form;
  515. }
  516. /**
  517. * Implements hook_theme().
  518. */
  519. function i18n_node_theme() {
  520. return array(
  521. 'i18n_node_select_translation' => array(
  522. 'render element' => 'element',
  523. 'file' => 'i18n_node.pages.inc',
  524. ),
  525. );
  526. }
  527. /**
  528. * Shorthand for translating node type strings
  529. *
  530. * @param $type
  531. * Node type name or full object
  532. */
  533. function i18n_node_translate_type($type, $property = 'name', $source = NULL, $options = array()) {
  534. if (is_object($type)) {
  535. $source = $type->$property;
  536. $type = $type->type;
  537. }
  538. return i18n_string_translate(array('node', 'type', $type, $property), $source, $options);
  539. }
  540. /**
  541. * Get translated node type name (unfiltered)
  542. *
  543. * @param string $type
  544. * Node type.
  545. * @param string $name
  546. * Optional node type name.
  547. */
  548. function i18n_node_type_name($type, $name = NULL) {
  549. $name = isset($name) ? $name : node_type_get_name($type);
  550. return i18n_string_translate(array('node', 'type', $type, 'name'), $name, array('sanitize' => FALSE));
  551. }
  552. /**
  553. * Check whether this is a language enabled node type
  554. *
  555. * @param $type
  556. * Node, node type object, or node type name
  557. */
  558. function i18n_node_type_enabled($type) {
  559. $type = is_object($type) ? $type->type : $type;
  560. $mode = variable_get('language_content_type_' . $type, 0);
  561. return $mode == 1 || $mode == 2; // 2 == TRANSLATION_ENABLED
  562. }