i18n_node.module 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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) {
  242. if (i18n_node_type_enabled($node)) {
  243. $node->content['language'] = array(
  244. '#type' => 'item',
  245. '#title' => t('Language'),
  246. '#markup' => i18n_language_name($node->language),
  247. );
  248. }
  249. }
  250. /**
  251. * Implements hook_node_view_alter().
  252. *
  253. * Handles links for extended languages. Sets current interface language.
  254. */
  255. function i18n_node_node_view_alter(&$build) {
  256. if (isset($build['#node'])) {
  257. $node = $build['#node'];
  258. }
  259. // Hide node translation links.
  260. if (variable_get('i18n_hide_translation_links', 0)) {
  261. if (isset($build['links']['translation'])) {
  262. unset($build['links']['translation']);
  263. }
  264. }
  265. elseif (!empty($node->tnid) && !empty($build['links']['translation']) && i18n_node_language_mode($node) == I18N_LANGUAGE_EXTENDED) {
  266. // We only get links for translations for enabled languages
  267. // Set the right languages if language support is extended but not visible.
  268. $links = &$build['links']['translation']['#links'];
  269. $translations = translation_node_get_translations($node->tnid);
  270. foreach (i18n_node_language_list($node) as $langcode => $langname) {
  271. $index = 'translation_' . $langcode;
  272. if ($langcode != $node->language && isset($translations[$langcode]) && $translations[$langcode]->status && !isset($links[$index])) {
  273. // This a published translation to a disabled language. As the node is language extended, display the linkso
  274. // These links shouldn't switch the interface, though they have a language so the right language icon will be added
  275. $language = i18n_language_object($langcode);
  276. $links[$index] = array(
  277. 'href' => 'node/' . $translations[$langcode]->nid,
  278. 'title' => $language->native,
  279. 'language' => $language,
  280. 'attributes' => array(
  281. 'title' => $translations[$langcode]->title,
  282. 'class' => array('translation-link'),
  283. ),
  284. );
  285. }
  286. }
  287. }
  288. }
  289. /**
  290. * Implements hook_node_type_insert()
  291. */
  292. function i18n_node_node_type_insert($info) {
  293. i18n_node_node_type_update($info);
  294. }
  295. /**
  296. * Implements hook_node_type_update()
  297. */
  298. function i18n_node_node_type_update($info) {
  299. if (!empty($info->old_type) && $info->old_type != $info->type) {
  300. i18n_string_update_context("node:type:$info->old_type:*", "node:type:$info->type:*");
  301. }
  302. i18n_string_object_update('node_type', $info);
  303. }
  304. /**
  305. * Implements hook_node_type_delete()
  306. */
  307. function i18n_node_node_type_delete($info) {
  308. i18n_string_object_remove('node_type', $info);
  309. }
  310. /**
  311. * Implements hook_elements().
  312. *
  313. * Add a process callback for textfields.
  314. *
  315. * * @todo Update D7
  316. */
  317. /*
  318. function i18n_node_elements() {
  319. $type = array();
  320. $type['textfield'] = array('#process' => array('i18n_node_textfield_process'));
  321. return $type;
  322. }
  323. */
  324. /**
  325. * Process callback for textfield elements.
  326. *
  327. * When editing or translating a node, set Javascript to rewrite autocomplete
  328. * paths to use the node language prefix rather than the current content one.
  329. *
  330. * @todo Update D7
  331. */
  332. function i18n_node_textfield_process($element) {
  333. global $language;
  334. static $sent = FALSE;
  335. // Ensure we send the Javascript only once.
  336. if (!$sent && isset($element['#autocomplete_path']) && !empty($element['#autocomplete_path']) && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_DEFAULT) != LANGUAGE_NEGOTIATION_DEFAULT) {
  337. // Add a JS file for node forms.
  338. // Determine if we are either editing or translating an existing node.
  339. // We can't act on regular node creation because we don't have a specified
  340. // node language.
  341. $node_edit = $node = menu_get_object() && arg(2) == 'edit' && isset($node->language) && !empty($node->language);
  342. $node_translate = arg(0) == 'node' && arg(1) == 'add' && !empty($_GET['translation']) && !empty($_GET['language']);
  343. if ($node_edit || $node_translate) {
  344. $node_language = $node_edit ? $node->language : $_GET['language'];
  345. // Only needed if the node language is different from the interface one.
  346. if ($node_language != $language->language) {
  347. $languages = language_list();
  348. if (isset($languages[$node_language])) {
  349. drupal_add_js(drupal_get_path('module', 'i18n_node') . '/i18n_node.js');
  350. // Pass the interface and content language base paths.
  351. // Remove any trailing forward slash. Doing so prevents a mismatch
  352. // that occurs when a language has no prefix and hence gets a path
  353. // with a trailing forward slash.
  354. $interface = rtrim(url('', array('absolute' => TRUE)), '/');
  355. $content = rtrim(url('', array('absolute' => TRUE, 'language' => $languages[$node_language])), '/');
  356. $data = array('interface_path' => $interface, 'content_path' => $content);
  357. drupal_add_js(array('i18n' => $data), 'setting');
  358. }
  359. }
  360. }
  361. $sent = TRUE;
  362. }
  363. return $element;
  364. }
  365. /**
  366. * Implements hook_form_FORM_ID_alter().
  367. */
  368. function i18n_node_form_search_form_alter(&$form, &$form_state) {
  369. // Advanced search form. Add language and localize content type names
  370. if ($form['module']['#value'] == 'node' && !empty($form['advanced'])) {
  371. // @todo Handle language search conditions
  372. //$form['advanced']['language'] = _i18n_language_select();
  373. if (!empty($form['advanced']['type'])) {
  374. foreach ($form['advanced']['type']['#options'] as $type => $name) {
  375. $form['advanced']['type']['#options'][$type] = i18n_node_translate_type($type, 'name', $name);
  376. }
  377. }
  378. }
  379. }
  380. /**
  381. * Implements hook_form_FORM_ID_alter().
  382. */
  383. function i18n_node_form_node_type_form_alter(&$form, &$form_state) {
  384. if (isset($form['type'])) {
  385. $disabled = !i18n_node_type_enabled($form['#node_type']);
  386. $form['i18n'] = array(
  387. '#type' => 'fieldset',
  388. '#title' => t('Multilingual settings'),
  389. '#collapsible' => TRUE,
  390. '#collapsed' => TRUE,
  391. '#group' => 'additional_settings',
  392. '#attributes' => array(
  393. 'class' => array('i18n-node-type-settings-form'),
  394. ),
  395. '#description' => t('Extended multilingual options provided by Internationalization module.'),
  396. '#disabled' => $disabled,
  397. );
  398. // Some settings about node languages. Add variables for node type from variable definition
  399. if ($form['#node_type']->type) {
  400. variable_type_include('node_type');
  401. $form['i18n'] += node_variable_type_subform($form['#node_type']->type, array('i18n_node_options', 'i18n_node_default_language_for', 'i18n_node_extended'));
  402. // Only show custom default language field if "current" is checked.
  403. $form['i18n']['i18n_node_default_language_for']['#states'] = array(
  404. 'visible' => array(
  405. ':input[name="i18n_node_options[current]"]' => array('checked' => TRUE),
  406. ),
  407. 'required' => array(
  408. ':input[name="i18n_node_options[current]"]' => array('checked' => TRUE),
  409. ),
  410. );
  411. }
  412. // Add disabled message
  413. if ($disabled) {
  414. $form['i18n']['#description'] .= ' <em>' . t('These will be available only when you enable Multilingual support in Publishing options above.') . '</em>';
  415. foreach (element_children($form['i18n']) as $key) {
  416. $form['i18n'][$key]['#disabled'] = TRUE;
  417. }
  418. }
  419. }
  420. }
  421. /**
  422. * Implements hook_form_BASE_FORM_ID_alter().
  423. */
  424. function i18n_node_form_node_form_alter(&$form, $form_state) {
  425. $node = $form['#node'];
  426. /**
  427. * i18n has to override locale.module
  428. * drupal_alter() fails to order modules correctly in some cases
  429. * for example specific hooks like hook_form_BASE_FORM_ID_alter
  430. *
  431. * its not possbile to reorder hook_form_BASE_FORM_ID_alter with
  432. * hook_module_implements_alter
  433. *
  434. * @see http://drupal.org/node/765860
  435. */
  436. // Replace core's node submit callback with our own,
  437. // in order to translate the node type name.
  438. $key = array_search('node_form_submit', $form['actions']['submit']['#submit']);
  439. if ($key !== FALSE) {
  440. $form['actions']['submit']['#submit'][$key] = 'i18n_node_form_submit';
  441. }
  442. // call a 'private' implemenation of i18n_node_form_node_form_alter()
  443. $form['#after_build'][] = '_i18n_node_form_node_form_alter';
  444. }
  445. /**
  446. * Replacement for core's node_form_submit(), taking care of
  447. * translating node type names.
  448. */
  449. function i18n_node_form_submit($form, &$form_state) {
  450. $node = node_form_submit_build_node($form, $form_state);
  451. $insert = empty($node->nid);
  452. node_save($node);
  453. $node_link = l(t('view'), 'node/' . $node->nid);
  454. $type_name = i18n_node_type_name($node->type);
  455. $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
  456. $t_args = array('@type' => $type_name, '%title' => $node->title);
  457. if ($insert) {
  458. watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
  459. drupal_set_message(t('@type %title has been created.', $t_args));
  460. }
  461. else {
  462. watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
  463. drupal_set_message(t('@type %title has been updated.', $t_args));
  464. }
  465. if ($node->nid) {
  466. $form_state['values']['nid'] = $node->nid;
  467. $form_state['nid'] = $node->nid;
  468. $form_state['redirect'] = node_access('view', $node) ? 'node/' . $node->nid : '<front>';
  469. }
  470. else {
  471. // In the unlikely case something went wrong on save, the node will be
  472. // rebuilt and node form redisplayed the same way as in preview.
  473. drupal_set_message(t('The post could not be saved.'), 'error');
  474. $form_state['rebuild'] = TRUE;
  475. }
  476. // Clear the page and block caches.
  477. cache_clear_all();
  478. }
  479. /**
  480. * Implements hook_form_BASE_FORM_ID_alter().
  481. * Called by i18n_node_form_node_form_alter
  482. */
  483. function _i18n_node_form_node_form_alter($form, &$form_state) {
  484. $node = $form['#node'];
  485. if (i18n_node_type_enabled($node)) {
  486. if (!empty($form['language']['#options'])) {
  487. $form['language']['#options'] = i18n_node_language_list($node, TRUE, TRUE);
  488. }
  489. }
  490. elseif (variable_get('i18n_node_default_language_none', 0) && !isset($form['#node']->nid)) {
  491. // Only do this if the language is really disabled
  492. if (variable_get('language_content_type_' . $node->type, 0) == 0) {
  493. // Override locale module setting default language to nodes. It is already in form_state.
  494. $form['language']['#value'] = $form_state['values']['language'] = LANGUAGE_NONE;
  495. }
  496. }
  497. // Translate field names for title and body for the node edit form.
  498. if (!empty($form['title']['#title'])) {
  499. $form['title']['#title'] = i18n_node_translate_type($node->type, 'title_label', $form['title']['#title']);
  500. }
  501. if (!empty($form['body_field']['body']['#title'])) {
  502. $form['body_field']['body']['#title'] = i18n_node_translate_type($node->type, 'body', $form['body_field']['body']['#title']);
  503. }
  504. // Translate page title for node/add/% and node/%/edit pages.
  505. if (empty($node->nid) && strpos($_GET['q'], 'node/add/' . str_replace('_', '-', $node->type)) === 0) {
  506. drupal_set_title(t('Create @name', array('@name' => i18n_node_type_name($node->type))), PASS_THROUGH);
  507. }
  508. elseif (!empty($node->nid) && $_GET['q'] == 'node/' . $node->nid . '/edit') {
  509. drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => i18n_node_type_name($node->type), '@title' => $node->title)), PASS_THROUGH);
  510. }
  511. return $form;
  512. }
  513. /**
  514. * Implements hook_theme().
  515. */
  516. function i18n_node_theme() {
  517. return array(
  518. 'i18n_node_select_translation' => array(
  519. 'render element' => 'element',
  520. 'file' => 'i18n_node.pages.inc',
  521. ),
  522. );
  523. }
  524. /**
  525. * Shorthand for translating node type strings
  526. *
  527. * @param $type
  528. * Node type name or full object
  529. */
  530. function i18n_node_translate_type($type, $property = 'name', $source = NULL, $options = array()) {
  531. if (is_object($type)) {
  532. $source = $type->$property;
  533. $type = $type->type;
  534. }
  535. return i18n_string_translate(array('node', 'type', $type, $property), $source, $options);
  536. }
  537. /**
  538. * Get translated node type name (unfiltered)
  539. *
  540. * @param string $type
  541. * Node type.
  542. * @param string $name
  543. * Optional node type name.
  544. */
  545. function i18n_node_type_name($type, $name = NULL) {
  546. $name = isset($name) ? $name : node_type_get_name($type);
  547. return i18n_string_translate(array('node', 'type', $type, 'name'), $name, array('sanitize' => FALSE));
  548. }
  549. /**
  550. * Check whether this is a language enabled node type
  551. *
  552. * @param $type
  553. * Node, node type object, or node type name
  554. */
  555. function i18n_node_type_enabled($type) {
  556. $type = is_object($type) ? $type->type : $type;
  557. $mode = variable_get('language_content_type_' . $type, 0);
  558. return $mode == 1 || $mode == 2; // 2 == TRANSLATION_ENABLED
  559. }