locale.module 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. <?php
  2. /**
  3. * @file
  4. * Add language handling functionality and enables the translation of the
  5. * user interface to languages other than English.
  6. *
  7. * When enabled, multiple languages can be set up. The site interface
  8. * can be displayed in different languages, as well as nodes can have languages
  9. * assigned. The setup of languages and translations is completely web based.
  10. * Gettext portable object files are supported.
  11. */
  12. // ---------------------------------------------------------------------------------
  13. // Hook implementations
  14. /**
  15. * Implements hook_help().
  16. */
  17. function locale_help($path, $arg) {
  18. switch ($path) {
  19. case 'admin/help#locale':
  20. $output = '';
  21. $output .= '<h3>' . t('About') . '</h3>';
  22. $output .= '<p>' . t('The Locale module allows your Drupal site to be presented in languages other than the default English, and to be multilingual. The Locale module works by maintaining a database of translations, and examining text as it is about to be displayed. When a translation of the text is available in the language to be displayed, the translation is displayed rather than the original text. When a translation is unavailable, the original text is displayed, and then stored for review by a translator. For more information, see the online handbook entry for <a href="@locale">Locale module</a>.', array('@locale' => 'http://drupal.org/documentation/modules/locale/')) . '</p>';
  23. $output .= '<h3>' . t('Uses') . '</h3>';
  24. $output .= '<dl>';
  25. $output .= '<dt>' . t('Translating interface text') . '</dt>';
  26. $output .= '<dd>' . t('Translations of text in the Drupal interface may be provided by:');
  27. $output .= '<ul>';
  28. $output .= '<li>' . t("Translating within your site, using the Locale module's integrated <a href='@translate'>translation interface</a>.", array('@translate' => url('admin/config/regional/translate'))) . '</li>';
  29. $output .= '<li>' . t('Importing files from a set of existing translations, known as a translation package. A translation package enables the display of a specific version of Drupal in a specific language, and contains files in the Gettext Portable Object (<em>.po</em>) format. Although not all languages are available for every version of Drupal, translation packages for many languages are available for download from the <a href="@translations">Drupal translations page</a>.', array('@translations' => 'http://localize.drupal.org')) . '</li>';
  30. $output .= '<li>' . t("If an existing translation package does not meet your needs, the Gettext Portable Object (<em>.po</em>) files within a package may be modified, or new <em>.po</em> files may be created, using a desktop Gettext editor. The Locale module's <a href='@import'>import</a> feature allows the translated strings from a new or modified <em>.po</em> file to be added to your site. The Locale module's <a href='@export'>export</a> feature generates files from your site's translated strings, that can either be shared with others or edited offline by a Gettext translation editor.", array('@import' => url('admin/config/regional/translate/import'), '@export' => url('admin/config/regional/translate/export'))) . '</li>';
  31. $output .= '</ul></dd>';
  32. $output .= '<dt>' . t('Configuring a multilingual site') . '</dt>';
  33. $output .= '<dd>' . t("Language negotiation allows your site to automatically change language based on the domain or path used for each request. Users may (optionally) select their preferred language on their <em>My account</em> page, and your site can be configured to honor a web browser's preferred language settings. Site content can be translated using the <a href='@content-help'>Content translation module</a>.", array('@content-help' => url('admin/help/translation'))) . '</dd>';
  34. $output .= '</dl>';
  35. return $output;
  36. case 'admin/config/regional/language':
  37. $output = '<p>' . t('With multiple languages enabled, interface text can be translated, registered users may select their preferred language, and authors can assign a specific language to content. <a href="@translations">Download contributed translations</a> from Drupal.org.', array('@translations' => 'http://localize.drupal.org')) . '</p>';
  38. return $output;
  39. case 'admin/config/regional/language/add':
  40. return '<p>' . t('Add a language to be supported by your site. If your desired language is not available in the <em>Language name</em> drop-down, click <em>Custom language</em> and provide a language code and other details manually. When providing a language code manually, be sure to enter a standardized language code, since this code may be used by browsers to determine an appropriate display language.') . '</p>';
  41. case 'admin/config/regional/language/configure':
  42. $output = '<p>' . t("Define how to decide which language is used to display page elements (primarily text provided by Drupal and modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Define the order of evaluation of language detection methods on this page.") . '</p>';
  43. return $output;
  44. case 'admin/config/regional/language/configure/session':
  45. $output = '<p>' . t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '</p>';
  46. return $output;
  47. case 'admin/config/regional/translate':
  48. $output = '<p>' . t('This page provides an overview of available translatable strings. Drupal displays translatable strings in text groups; modules may define additional text groups containing other translatable strings. Because text groups provide a method of grouping related strings, they are often used to focus translation efforts on specific areas of the Drupal interface.') . '</p>';
  49. $output .= '<p>' . t('See the <a href="@languages">Languages page</a> for more information on adding support for additional languages.', array('@languages' => url('admin/config/regional/language'))) . '</p>';
  50. return $output;
  51. case 'admin/config/regional/translate/import':
  52. $output = '<p>' . t('This page imports the translated strings contained in an individual Gettext Portable Object (<em>.po</em>) file. Normally distributed as part of a translation package (each translation package may contain several <em>.po</em> files), a <em>.po</em> file may need to be imported after offline editing in a Gettext translation editor. Importing an individual <em>.po</em> file may be a lengthy process.') . '</p>';
  53. $output .= '<p>' . t('Note that the <em>.po</em> files within a translation package are imported automatically (if available) when new modules or themes are enabled, or as new languages are added. Since this page only allows the import of one <em>.po</em> file at a time, it may be simpler to download and extract a translation package into your Drupal installation directory and <a href="@language-add">add the language</a> (which automatically imports all <em>.po</em> files within the package). Translation packages are available for download on the <a href="@translations">Drupal translation page</a>.', array('@language-add' => url('admin/config/regional/language/add'), '@translations' => 'http://localize.drupal.org')) . '</p>';
  54. return $output;
  55. case 'admin/config/regional/translate/export':
  56. return '<p>' . t('This page exports the translated strings used by your site. An export file may be in Gettext Portable Object (<em>.po</em>) form, which includes both the original string and the translation (used to share translations with others), or in Gettext Portable Object Template (<em>.pot</em>) form, which includes the original strings only (used to create new translations with a Gettext translation editor).') . '</p>';
  57. case 'admin/config/regional/translate/translate':
  58. return '<p>' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: For translation tasks involving many strings, it may be more convenient to <a href="@export">export</a> strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings found within a specific text group or in a specific language.', array('@export' => url('admin/config/regional/translate/export'))) . '</p>';
  59. case 'admin/structure/block/manage/%/%':
  60. if ($arg[4] == 'locale' && $arg[5] == 'language') {
  61. return '<p>' . t('This block is only shown if <a href="@languages">at least two languages are enabled</a> and <a href="@configuration">language negotiation</a> is set to <em>URL</em> or <em>Session</em>.', array('@languages' => url('admin/config/regional/language'), '@configuration' => url('admin/config/regional/language/configure'))) . '</p>';
  62. }
  63. break;
  64. }
  65. }
  66. /**
  67. * Implements hook_menu().
  68. */
  69. function locale_menu() {
  70. // Manage languages
  71. $items['admin/config/regional/language'] = array(
  72. 'title' => 'Languages',
  73. 'description' => 'Configure languages for content and the user interface.',
  74. 'page callback' => 'drupal_get_form',
  75. 'page arguments' => array('locale_languages_overview_form'),
  76. 'access arguments' => array('administer languages'),
  77. 'file' => 'locale.admin.inc',
  78. 'weight' => -10,
  79. );
  80. $items['admin/config/regional/language/overview'] = array(
  81. 'title' => 'List',
  82. 'weight' => 0,
  83. 'type' => MENU_DEFAULT_LOCAL_TASK,
  84. );
  85. $items['admin/config/regional/language/add'] = array(
  86. 'title' => 'Add language',
  87. 'page callback' => 'locale_languages_add_screen', // two forms concatenated
  88. 'access arguments' => array('administer languages'),
  89. 'weight' => 5,
  90. 'type' => MENU_LOCAL_ACTION,
  91. 'file' => 'locale.admin.inc',
  92. );
  93. $items['admin/config/regional/language/configure'] = array(
  94. 'title' => 'Detection and selection',
  95. 'page callback' => 'drupal_get_form',
  96. 'page arguments' => array('locale_languages_configure_form'),
  97. 'access arguments' => array('administer languages'),
  98. 'weight' => 10,
  99. 'file' => 'locale.admin.inc',
  100. 'type' => MENU_LOCAL_TASK,
  101. );
  102. $items['admin/config/regional/language/configure/url'] = array(
  103. 'title' => 'URL language detection configuration',
  104. 'page callback' => 'drupal_get_form',
  105. 'page arguments' => array('locale_language_providers_url_form'),
  106. 'access arguments' => array('administer languages'),
  107. 'file' => 'locale.admin.inc',
  108. 'type' => MENU_VISIBLE_IN_BREADCRUMB,
  109. );
  110. $items['admin/config/regional/language/configure/session'] = array(
  111. 'title' => 'Session language detection configuration',
  112. 'page callback' => 'drupal_get_form',
  113. 'page arguments' => array('locale_language_providers_session_form'),
  114. 'access arguments' => array('administer languages'),
  115. 'file' => 'locale.admin.inc',
  116. 'type' => MENU_VISIBLE_IN_BREADCRUMB,
  117. );
  118. $items['admin/config/regional/language/edit/%'] = array(
  119. 'title' => 'Edit language',
  120. 'page callback' => 'drupal_get_form',
  121. 'page arguments' => array('locale_languages_edit_form', 5),
  122. 'access arguments' => array('administer languages'),
  123. 'file' => 'locale.admin.inc',
  124. );
  125. $items['admin/config/regional/language/delete/%'] = array(
  126. 'title' => 'Confirm',
  127. 'page callback' => 'drupal_get_form',
  128. 'page arguments' => array('locale_languages_delete_form', 5),
  129. 'access arguments' => array('administer languages'),
  130. 'file' => 'locale.admin.inc',
  131. );
  132. // Translation functionality
  133. $items['admin/config/regional/translate'] = array(
  134. 'title' => 'Translate interface',
  135. 'description' => 'Translate the built in interface and optionally other text.',
  136. 'page callback' => 'locale_translate_overview_screen',
  137. 'access arguments' => array('translate interface'),
  138. 'file' => 'locale.admin.inc',
  139. 'weight' => -5,
  140. );
  141. $items['admin/config/regional/translate/overview'] = array(
  142. 'title' => 'Overview',
  143. 'weight' => 0,
  144. 'type' => MENU_DEFAULT_LOCAL_TASK,
  145. );
  146. $items['admin/config/regional/translate/translate'] = array(
  147. 'title' => 'Translate',
  148. 'weight' => 10,
  149. 'type' => MENU_LOCAL_TASK,
  150. 'page callback' => 'locale_translate_seek_screen', // search results and form concatenated
  151. 'access arguments' => array('translate interface'),
  152. 'file' => 'locale.admin.inc',
  153. );
  154. $items['admin/config/regional/translate/import'] = array(
  155. 'title' => 'Import',
  156. 'page callback' => 'drupal_get_form',
  157. 'page arguments' => array('locale_translate_import_form'),
  158. 'access arguments' => array('translate interface'),
  159. 'weight' => 20,
  160. 'type' => MENU_LOCAL_TASK,
  161. 'file' => 'locale.admin.inc',
  162. );
  163. $items['admin/config/regional/translate/export'] = array(
  164. 'title' => 'Export',
  165. 'page callback' => 'locale_translate_export_screen', // possibly multiple forms concatenated
  166. 'access arguments' => array('translate interface'),
  167. 'weight' => 30,
  168. 'type' => MENU_LOCAL_TASK,
  169. 'file' => 'locale.admin.inc',
  170. );
  171. $items['admin/config/regional/translate/edit/%'] = array(
  172. 'title' => 'Edit string',
  173. 'page callback' => 'drupal_get_form',
  174. 'page arguments' => array('locale_translate_edit_form', 5),
  175. 'access arguments' => array('translate interface'),
  176. 'file' => 'locale.admin.inc',
  177. );
  178. $items['admin/config/regional/translate/delete/%'] = array(
  179. 'title' => 'Delete string',
  180. 'page callback' => 'locale_translate_delete_page',
  181. 'page arguments' => array(5),
  182. 'access arguments' => array('translate interface'),
  183. 'file' => 'locale.admin.inc',
  184. );
  185. // Localize date formats.
  186. $items['admin/config/regional/date-time/locale'] = array(
  187. 'title' => 'Localize',
  188. 'description' => 'Configure date formats for each locale',
  189. 'page callback' => 'locale_date_format_language_overview_page',
  190. 'access arguments' => array('administer site configuration'),
  191. 'type' => MENU_LOCAL_TASK,
  192. 'weight' => -8,
  193. 'file' => 'locale.admin.inc',
  194. );
  195. $items['admin/config/regional/date-time/locale/%/edit'] = array(
  196. 'title' => 'Localize date formats',
  197. 'description' => 'Configure date formats for each locale',
  198. 'page callback' => 'drupal_get_form',
  199. 'page arguments' => array('locale_date_format_form', 5),
  200. 'access arguments' => array('administer site configuration'),
  201. 'file' => 'locale.admin.inc',
  202. );
  203. $items['admin/config/regional/date-time/locale/%/reset'] = array(
  204. 'title' => 'Reset date formats',
  205. 'description' => 'Reset localized date formats to global defaults',
  206. 'page callback' => 'drupal_get_form',
  207. 'page arguments' => array('locale_date_format_reset_form', 5),
  208. 'access arguments' => array('administer site configuration'),
  209. 'file' => 'locale.admin.inc',
  210. );
  211. return $items;
  212. }
  213. /**
  214. * Implements hook_init().
  215. *
  216. * Initialize date formats according to the user's current locale.
  217. */
  218. function locale_init() {
  219. global $conf, $language;
  220. include_once DRUPAL_ROOT . '/includes/locale.inc';
  221. // For each date type (e.g. long, short), get the localized date format
  222. // for the user's current language and override the default setting for it
  223. // in $conf. This should happen on all pages except the date and time formats
  224. // settings page, where we want to display the site default and not the
  225. // localized version.
  226. if (strpos($_GET['q'], 'admin/config/regional/date-time/formats') !== 0) {
  227. $languages = array($language->language);
  228. // Setup appropriate date formats for this locale.
  229. $formats = locale_get_localized_date_format($languages);
  230. foreach ($formats as $format_type => $format) {
  231. $conf[$format_type] = $format;
  232. }
  233. }
  234. }
  235. /**
  236. * Implements hook_permission().
  237. */
  238. function locale_permission() {
  239. return array(
  240. 'administer languages' => array(
  241. 'title' => t('Administer languages'),
  242. ),
  243. 'translate interface' => array(
  244. 'title' => t('Translate interface texts'),
  245. 'restrict access' => TRUE,
  246. ),
  247. );
  248. }
  249. /**
  250. * Implements hook_locale().
  251. */
  252. function locale_locale($op = 'groups') {
  253. switch ($op) {
  254. case 'groups':
  255. return array('default' => t('Built-in interface'));
  256. }
  257. }
  258. /**
  259. * Form builder callback to display language selection widget.
  260. *
  261. * @ingroup forms
  262. * @see locale_form_alter()
  263. */
  264. function locale_language_selector_form(&$form, &$form_state, $user) {
  265. global $language;
  266. $languages = language_list('enabled');
  267. $languages = $languages[1];
  268. // If the user is being created, we set the user language to the page language.
  269. $user_preferred_language = $user->uid ? user_preferred_language($user) : $language;
  270. $names = array();
  271. foreach ($languages as $langcode => $item) {
  272. $name = t($item->name);
  273. $names[$langcode] = $name . ($item->native != $name ? ' (' . $item->native . ')' : '');
  274. }
  275. $form['locale'] = array(
  276. '#type' => 'fieldset',
  277. '#title' => t('Language settings'),
  278. '#weight' => 1,
  279. '#access' => ($form['#user_category'] == 'account' || ($form['#user_category'] == 'register' && user_access('administer users'))),
  280. );
  281. // Get language negotiation settings.
  282. $mode = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT;
  283. $form['locale']['language'] = array(
  284. '#type' => (count($names) <= 5 ? 'radios' : 'select'),
  285. '#title' => t('Language'),
  286. '#default_value' => $user_preferred_language->language,
  287. '#options' => $names,
  288. '#description' => $mode ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."),
  289. );
  290. }
  291. /**
  292. * Implements hook_form_FORM_ID_alter().
  293. */
  294. function locale_form_path_admin_form_alter(&$form, &$form_state) {
  295. $form['language'] = array(
  296. '#type' => 'select',
  297. '#title' => t('Language'),
  298. '#options' => array(LANGUAGE_NONE => t('All languages')) + locale_language_list('name'),
  299. '#default_value' => $form['language']['#value'],
  300. '#weight' => -10,
  301. '#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for <em>All languages</em>.'),
  302. );
  303. }
  304. /**
  305. * Implements hook_form_FORM_ID_alter().
  306. */
  307. function locale_form_node_type_form_alter(&$form, &$form_state) {
  308. if (isset($form['type'])) {
  309. $form['workflow']['language_content_type'] = array(
  310. '#type' => 'radios',
  311. '#title' => t('Multilingual support'),
  312. '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),
  313. '#options' => array(t('Disabled'), t('Enabled')),
  314. '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),
  315. );
  316. }
  317. }
  318. /**
  319. * Return whether the given content type has multilingual support.
  320. *
  321. * @return
  322. * True if multilingual support is enabled.
  323. */
  324. function locale_multilingual_node_type($type_name) {
  325. return (bool) variable_get('language_content_type_' . $type_name, 0);
  326. }
  327. /**
  328. * Implements hook_form_alter().
  329. *
  330. * Adds language fields to user forms.
  331. */
  332. function locale_form_alter(&$form, &$form_state, $form_id) {
  333. // Only alter user forms if there is more than one language.
  334. if (drupal_multilingual()) {
  335. // Display language selector when either creating a user on the admin
  336. // interface or editing a user account.
  337. if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
  338. locale_language_selector_form($form, $form_state, $form['#user']);
  339. }
  340. }
  341. }
  342. /**
  343. * Implements hook_form_BASE_FORM_ID_alter().
  344. */
  345. function locale_form_node_form_alter(&$form, &$form_state) {
  346. if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) {
  347. $form['language'] = array(
  348. '#type' => 'select',
  349. '#title' => t('Language'),
  350. '#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''),
  351. '#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'),
  352. );
  353. }
  354. // Node type without language selector: assign the default for new nodes
  355. elseif (!isset($form['#node']->nid)) {
  356. $default = language_default();
  357. $form['language'] = array(
  358. '#type' => 'value',
  359. '#value' => $default->language
  360. );
  361. }
  362. $form['#submit'][] = 'locale_field_node_form_submit';
  363. }
  364. /**
  365. * Form submit handler for node_form().
  366. *
  367. * This submit handler needs to run before entity_form_submit_build_entity()
  368. * is invoked by node_form_submit_build_node(), because it alters the values of
  369. * attached fields. Therefore, it cannot be a hook_node_submit() implementation.
  370. */
  371. function locale_field_node_form_submit($form, &$form_state) {
  372. locale_field_entity_form_submit('node', $form, $form_state);
  373. }
  374. /**
  375. * Implements hook_form_FORM_ID_alter().
  376. */
  377. function locale_form_comment_form_alter(&$form, &$form_state, $form_id) {
  378. // If a content type has multilingual support we set the content language as
  379. // comment language.
  380. if ($form['language']['#value'] == LANGUAGE_NONE && locale_multilingual_node_type($form['#node']->type)) {
  381. global $language_content;
  382. $form['language']['#value'] = $language_content->language;
  383. $submit_callback = 'locale_field_comment_form_submit';
  384. array_unshift($form['actions']['preview']['#submit'], $submit_callback);
  385. array_unshift($form['#submit'], $submit_callback);
  386. }
  387. }
  388. /**
  389. * Form submit handler for comment_form().
  390. *
  391. * This submit handler needs to run before entity_form_submit_build_entity()
  392. * is invoked by comment_form_submit_build_comment(), because it alters the
  393. * values of attached fields.
  394. */
  395. function locale_field_comment_form_submit($form, &$form_state) {
  396. locale_field_entity_form_submit('comment', $form, $form_state);
  397. }
  398. /**
  399. * Handles field language on submit for the given entity type.
  400. *
  401. * Checks if Locale is registered as a translation handler and handle possible
  402. * language changes.
  403. */
  404. function locale_field_entity_form_submit($entity_type, $form, &$form_state ) {
  405. if (field_has_translation_handler($entity_type, 'locale')) {
  406. $entity = (object) $form_state['values'];
  407. $current_language = entity_language($entity_type, $entity);
  408. list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  409. foreach (field_info_instances($entity_type, $bundle) as $instance) {
  410. $field_name = $instance['field_name'];
  411. $field = field_info_field($field_name);
  412. $previous_language = $form[$field_name]['#language'];
  413. // Handle a possible language change: new language values are inserted,
  414. // previous ones are deleted.
  415. if ($field['translatable'] && $previous_language != $current_language) {
  416. $form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
  417. $form_state['values'][$field_name][$previous_language] = array();
  418. }
  419. }
  420. }
  421. }
  422. /**
  423. * Implements hook_theme().
  424. */
  425. function locale_theme() {
  426. return array(
  427. 'locale_languages_overview_form' => array(
  428. 'render element' => 'form',
  429. ),
  430. 'locale_languages_configure_form' => array(
  431. 'render element' => 'form',
  432. ),
  433. 'locale_date_format_form' => array(
  434. 'render element' => 'form',
  435. ),
  436. );
  437. }
  438. /**
  439. * Implements hook_field_language_alter().
  440. */
  441. function locale_field_language_alter(&$display_language, $context) {
  442. // Do not apply core language fallback rules if they are disabled or if Locale
  443. // is not registered as a translation handler.
  444. if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {
  445. locale_field_language_fallback($display_language, $context['entity'], $context['language']);
  446. }
  447. }
  448. /**
  449. * Applies language fallback rules to the fields attached to the given entity.
  450. *
  451. * Core language fallback rules simply check if fields have a field translation
  452. * for the requested language code. If so the requested language is returned,
  453. * otherwise all the fallback candidates are inspected to see if there is a
  454. * field translation available in another language.
  455. * By default this is called by locale_field_language_alter(), but this
  456. * behavior can be disabled by setting the 'locale_field_language_fallback'
  457. * variable to FALSE.
  458. *
  459. * @param $display_language
  460. * A reference to an array of language codes keyed by field name.
  461. * @param $entity
  462. * The entity to be displayed.
  463. * @param $langcode
  464. * The language code $entity has to be displayed in.
  465. */
  466. function locale_field_language_fallback(&$display_language, $entity, $langcode) {
  467. // Lazily init fallback candidates to avoid unnecessary calls.
  468. $fallback_candidates = NULL;
  469. $field_languages = array();
  470. foreach ($display_language as $field_name => $field_language) {
  471. // If the requested language is defined for the current field use it,
  472. // otherwise search for a fallback value among the fallback candidates.
  473. if (isset($entity->{$field_name}[$langcode])) {
  474. $display_language[$field_name] = $langcode;
  475. }
  476. elseif (!empty($entity->{$field_name})) {
  477. if (!isset($fallback_candidates)) {
  478. require_once DRUPAL_ROOT . '/includes/language.inc';
  479. $fallback_candidates = language_fallback_get_candidates();
  480. }
  481. foreach ($fallback_candidates as $fallback_language) {
  482. if (isset($entity->{$field_name}[$fallback_language])) {
  483. $display_language[$field_name] = $fallback_language;
  484. break;
  485. }
  486. }
  487. }
  488. }
  489. }
  490. /**
  491. * Implements hook_entity_info_alter().
  492. */
  493. function locale_entity_info_alter(&$entity_info) {
  494. $entity_info['node']['translation']['locale'] = TRUE;
  495. if (isset($entity_info['comment'])) {
  496. $entity_info['comment']['translation']['locale'] = TRUE;
  497. }
  498. }
  499. /**
  500. * Implements hook_language_types_info().
  501. *
  502. * Defines the three core language types:
  503. * - Interface language is the only configurable language type in core. It is
  504. * used by t() as the default language if none is specified.
  505. * - Content language is by default non-configurable and inherits the interface
  506. * language negotiated value. It is used by the Field API to determine the
  507. * display language for fields if no explicit value is specified.
  508. * - URL language is by default non-configurable and is determined through the
  509. * URL language provider or the URL fallback provider if no language can be
  510. * detected. It is used by l() as the default language if none is specified.
  511. */
  512. function locale_language_types_info() {
  513. require_once DRUPAL_ROOT . '/includes/locale.inc';
  514. return array(
  515. LANGUAGE_TYPE_INTERFACE => array(
  516. 'name' => t('User interface text'),
  517. 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'),
  518. ),
  519. LANGUAGE_TYPE_CONTENT => array(
  520. 'name' => t('Content'),
  521. 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
  522. 'fixed' => array(LOCALE_LANGUAGE_NEGOTIATION_INTERFACE),
  523. ),
  524. LANGUAGE_TYPE_URL => array(
  525. 'fixed' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_URL_FALLBACK),
  526. ),
  527. );
  528. }
  529. /**
  530. * Implements hook_language_negotiation_info().
  531. */
  532. function locale_language_negotiation_info() {
  533. require_once DRUPAL_ROOT . '/includes/locale.inc';
  534. $file = 'includes/locale.inc';
  535. $providers = array();
  536. $providers[LOCALE_LANGUAGE_NEGOTIATION_URL] = array(
  537. 'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL),
  538. 'callbacks' => array(
  539. 'language' => 'locale_language_from_url',
  540. 'switcher' => 'locale_language_switcher_url',
  541. 'url_rewrite' => 'locale_language_url_rewrite_url',
  542. ),
  543. 'file' => $file,
  544. 'weight' => -8,
  545. 'name' => t('URL'),
  546. 'description' => t('Determine the language from the URL (Path prefix or domain).'),
  547. 'config' => 'admin/config/regional/language/configure/url',
  548. );
  549. $providers[LOCALE_LANGUAGE_NEGOTIATION_SESSION] = array(
  550. 'callbacks' => array(
  551. 'language' => 'locale_language_from_session',
  552. 'switcher' => 'locale_language_switcher_session',
  553. 'url_rewrite' => 'locale_language_url_rewrite_session',
  554. ),
  555. 'file' => $file,
  556. 'weight' => -6,
  557. 'name' => t('Session'),
  558. 'description' => t('Determine the language from a request/session parameter.'),
  559. 'config' => 'admin/config/regional/language/configure/session',
  560. );
  561. $providers[LOCALE_LANGUAGE_NEGOTIATION_USER] = array(
  562. 'callbacks' => array('language' => 'locale_language_from_user'),
  563. 'file' => $file,
  564. 'weight' => -4,
  565. 'name' => t('User'),
  566. 'description' => t("Follow the user's language preference."),
  567. );
  568. $providers[LOCALE_LANGUAGE_NEGOTIATION_BROWSER] = array(
  569. 'callbacks' => array('language' => 'locale_language_from_browser'),
  570. 'file' => $file,
  571. 'weight' => -2,
  572. 'cache' => 0,
  573. 'name' => t('Browser'),
  574. 'description' => t("Determine the language from the browser's language settings."),
  575. );
  576. $providers[LOCALE_LANGUAGE_NEGOTIATION_INTERFACE] = array(
  577. 'types' => array(LANGUAGE_TYPE_CONTENT),
  578. 'callbacks' => array('language' => 'locale_language_from_interface'),
  579. 'file' => $file,
  580. 'weight' => 8,
  581. 'name' => t('Interface'),
  582. 'description' => t('Use the detected interface language.'),
  583. );
  584. $providers[LOCALE_LANGUAGE_NEGOTIATION_URL_FALLBACK] = array(
  585. 'types' => array(LANGUAGE_TYPE_URL),
  586. 'callbacks' => array('language' => 'locale_language_url_fallback'),
  587. 'file' => $file,
  588. 'weight' => 8,
  589. 'name' => t('URL fallback'),
  590. 'description' => t('Use an already detected language for URLs if none is found.'),
  591. );
  592. return $providers;
  593. }
  594. /**
  595. * Implements hook_modules_enabled().
  596. */
  597. function locale_modules_enabled($modules) {
  598. include_once DRUPAL_ROOT . '/includes/language.inc';
  599. language_types_set();
  600. language_negotiation_purge();
  601. }
  602. /**
  603. * Implements hook_modules_disabled().
  604. */
  605. function locale_modules_disabled($modules) {
  606. locale_modules_enabled($modules);
  607. }
  608. // ---------------------------------------------------------------------------------
  609. // Locale core functionality
  610. /**
  611. * Provides interface translation services.
  612. *
  613. * This function is called from t() to translate a string if needed.
  614. *
  615. * @param $string
  616. * A string to look up translation for. If omitted, all the
  617. * cached strings will be returned in all languages already
  618. * used on the page.
  619. * @param $context
  620. * The context of this string.
  621. * @param $langcode
  622. * Language code to use for the lookup.
  623. */
  624. function locale($string = NULL, $context = NULL, $langcode = NULL) {
  625. global $language;
  626. // Use the advanced drupal_static() pattern, since this is called very often.
  627. static $drupal_static_fast;
  628. if (!isset($drupal_static_fast)) {
  629. $drupal_static_fast['locale'] = &drupal_static(__FUNCTION__);
  630. }
  631. $locale_t = &$drupal_static_fast['locale'];
  632. if (!isset($string)) {
  633. // Return all cached strings if no string was specified
  634. return $locale_t;
  635. }
  636. $langcode = isset($langcode) ? $langcode : $language->language;
  637. // Store database cached translations in a static variable. Only build the
  638. // cache after $language has been set to avoid an unnecessary cache rebuild.
  639. if (!isset($locale_t[$langcode]) && isset($language)) {
  640. $locale_t[$langcode] = array();
  641. // Disabling the usage of string caching allows a module to watch for
  642. // the exact list of strings used on a page. From a performance
  643. // perspective that is a really bad idea, so we have no user
  644. // interface for this. Be careful when turning this option off!
  645. if (variable_get('locale_cache_strings', 1) == 1) {
  646. if ($cache = cache_get('locale:' . $langcode, 'cache')) {
  647. $locale_t[$langcode] = $cache->data;
  648. }
  649. elseif (lock_acquire('locale_cache_' . $langcode)) {
  650. // Refresh database stored cache of translations for given language.
  651. // We only store short strings used in current version, to improve
  652. // performance and consume less memory.
  653. $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < :length", array(':language' => $langcode, ':version' => VERSION, ':length' => variable_get('locale_cache_length', 75)));
  654. foreach ($result as $data) {
  655. $locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
  656. }
  657. cache_set('locale:' . $langcode, $locale_t[$langcode]);
  658. lock_release('locale_cache_' . $langcode);
  659. }
  660. }
  661. }
  662. // If we have the translation cached, skip checking the database
  663. if (!isset($locale_t[$langcode][$context][$string])) {
  664. // We do not have this translation cached, so get it from the DB.
  665. $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
  666. ':language' => $langcode,
  667. ':source' => $string,
  668. ':context' => (string) $context,
  669. ))->fetchObject();
  670. if ($translation) {
  671. // We have the source string at least.
  672. // Cache translation string or TRUE if no translation exists.
  673. $locale_t[$langcode][$context][$string] = (empty($translation->translation) ? TRUE : $translation->translation);
  674. if ($translation->version != VERSION) {
  675. // This is the first use of this string under current Drupal version. Save version
  676. // and clear cache, to include the string into caching next time. Saved version is
  677. // also a string-history information for later pruning of the tables.
  678. db_update('locales_source')
  679. ->fields(array('version' => VERSION))
  680. ->condition('lid', $translation->lid)
  681. ->execute();
  682. cache_clear_all('locale:', 'cache', TRUE);
  683. }
  684. }
  685. else {
  686. // We don't have the source string, cache this as untranslated.
  687. db_merge('locales_source')
  688. ->insertFields(array(
  689. 'location' => request_uri(),
  690. 'version' => VERSION,
  691. ))
  692. ->key(array(
  693. 'source' => $string,
  694. 'context' => (string) $context,
  695. 'textgroup' => 'default',
  696. ))
  697. ->execute();
  698. $locale_t[$langcode][$context][$string] = TRUE;
  699. // Clear locale cache so this string can be added in a later request.
  700. cache_clear_all('locale:', 'cache', TRUE);
  701. }
  702. }
  703. return ($locale_t[$langcode][$context][$string] === TRUE ? $string : $locale_t[$langcode][$context][$string]);
  704. }
  705. /**
  706. * Reset static variables used by locale().
  707. */
  708. function locale_reset() {
  709. drupal_static_reset('locale');
  710. }
  711. /**
  712. * Returns plural form index for a specific number.
  713. *
  714. * The index is computed from the formula of this language.
  715. *
  716. * @param $count
  717. * Number to return plural for.
  718. * @param $langcode
  719. * Optional language code to translate to a language other than
  720. * what is used to display the page.
  721. *
  722. * @return
  723. * The numeric index of the plural variant to use for this $langcode and
  724. * $count combination or -1 if the language was not found or does not have a
  725. * plural formula.
  726. */
  727. function locale_get_plural($count, $langcode = NULL) {
  728. global $language;
  729. // Used to locally cache the plural formulas for all languages.
  730. $plural_formulas = &drupal_static(__FUNCTION__, array());
  731. // Used to store precomputed plural indexes corresponding to numbers
  732. // individually for each language.
  733. $plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array());
  734. $langcode = $langcode ? $langcode : $language->language;
  735. if (!isset($plural_indexes[$langcode][$count])) {
  736. // Retrieve and statically cache the plural formulas for all languages.
  737. if (empty($plural_formulas)) {
  738. foreach (language_list() as $installed_language) {
  739. $plural_formulas[$installed_language->language] = $installed_language->formula;
  740. }
  741. }
  742. // If there is a plural formula for the language, evaluate it for the given
  743. // $count and statically cache the result for the combination of language
  744. // and count, since the result will always be identical.
  745. if (!empty($plural_formulas[$langcode])) {
  746. // $n is used inside the expression in the eval().
  747. $n = $count;
  748. $plural_indexes[$langcode][$count] = @eval('return intval(' . $plural_formulas[$langcode] . ');');
  749. }
  750. // In case there is no plural formula for English (no imported translation
  751. // for English), use a default formula.
  752. elseif ($langcode == 'en') {
  753. $plural_indexes[$langcode][$count] = (int) ($count != 1);
  754. }
  755. // Otherwise, return -1 (unknown).
  756. else {
  757. $plural_indexes[$langcode][$count] = -1;
  758. }
  759. }
  760. return $plural_indexes[$langcode][$count];
  761. }
  762. /**
  763. * Returns a language name
  764. */
  765. function locale_language_name($lang) {
  766. $list = &drupal_static(__FUNCTION__);
  767. if (!isset($list)) {
  768. $list = locale_language_list();
  769. }
  770. return ($lang && isset($list[$lang])) ? $list[$lang] : t('All');
  771. }
  772. /**
  773. * Returns array of language names
  774. *
  775. * @param $field
  776. * 'name' => names in current language, localized
  777. * 'native' => native names
  778. * @param $all
  779. * Boolean to return all languages or only enabled ones
  780. */
  781. function locale_language_list($field = 'name', $all = FALSE) {
  782. if ($all) {
  783. $languages = language_list();
  784. }
  785. else {
  786. $languages = language_list('enabled');
  787. $languages = $languages[1];
  788. }
  789. $list = array();
  790. foreach ($languages as $language) {
  791. $list[$language->language] = ($field == 'name') ? t($language->name) : $language->$field;
  792. }
  793. return $list;
  794. }
  795. /**
  796. * Implements hook_modules_installed().
  797. */
  798. function locale_modules_installed($modules) {
  799. locale_system_update($modules);
  800. }
  801. /**
  802. * Implements hook_themes_enabled().
  803. *
  804. * @todo This is technically wrong. We must not import upon enabling, but upon
  805. * initial installation. The theme system is missing an installation hook.
  806. */
  807. function locale_themes_enabled($themes) {
  808. locale_system_update($themes);
  809. }
  810. /**
  811. * Imports translations when new modules or themes are installed.
  812. *
  813. * This function will either import translation for the component change
  814. * right away, or start a batch if more files need to be imported.
  815. *
  816. * @param $components
  817. * An array of component (theme and/or module) names to import
  818. * translations for.
  819. */
  820. function locale_system_update($components) {
  821. include_once DRUPAL_ROOT . '/includes/locale.inc';
  822. if ($batch = locale_batch_by_component($components)) {
  823. batch_set($batch);
  824. }
  825. }
  826. /**
  827. * Implements hook_js_alter().
  828. *
  829. * This function checks all JavaScript files currently added via drupal_add_js()
  830. * and invokes parsing if they have not yet been parsed for Drupal.t()
  831. * and Drupal.formatPlural() calls. Also refreshes the JavaScript translation
  832. * file if necessary, and adds it to the page.
  833. */
  834. function locale_js_alter(&$javascript) {
  835. global $language;
  836. $dir = 'public://' . variable_get('locale_js_directory', 'languages');
  837. $parsed = variable_get('javascript_parsed', array());
  838. $files = $new_files = FALSE;
  839. // Require because locale_js_alter() could be called without locale_init().
  840. require_once DRUPAL_ROOT . '/includes/locale.inc';
  841. foreach ($javascript as $item) {
  842. if ($item['type'] == 'file') {
  843. $files = TRUE;
  844. $filepath = $item['data'];
  845. if (!in_array($filepath, $parsed)) {
  846. // Don't parse our own translations files.
  847. if (substr($filepath, 0, strlen($dir)) != $dir) {
  848. _locale_parse_js_file($filepath);
  849. $parsed[] = $filepath;
  850. $new_files = TRUE;
  851. }
  852. }
  853. }
  854. }
  855. // If there are any new source files we parsed, invalidate existing
  856. // JavaScript translation files for all languages, adding the refresh
  857. // flags into the existing array.
  858. if ($new_files) {
  859. $parsed += _locale_invalidate_js();
  860. }
  861. // If necessary, rebuild the translation file for the current language.
  862. if (!empty($parsed['refresh:' . $language->language])) {
  863. // Don't clear the refresh flag on failure, so that another try will
  864. // be performed later.
  865. if (_locale_rebuild_js()) {
  866. unset($parsed['refresh:' . $language->language]);
  867. }
  868. // Store any changes after refresh was attempted.
  869. variable_set('javascript_parsed', $parsed);
  870. }
  871. // If no refresh was attempted, but we have new source files, we need
  872. // to store them too. This occurs if current page is in English.
  873. elseif ($new_files) {
  874. variable_set('javascript_parsed', $parsed);
  875. }
  876. // Add the translation JavaScript file to the page.
  877. if ($files && !empty($language->javascript)) {
  878. // Add the translation JavaScript file to the page.
  879. $file = $dir . '/' . $language->language . '_' . $language->javascript . '.js';
  880. $javascript[$file] = drupal_js_defaults($file);
  881. }
  882. }
  883. /**
  884. * Implements hook_css_alter().
  885. *
  886. * This function checks all CSS files currently added via drupal_add_css() and
  887. * and checks to see if a related right to left CSS file should be included.
  888. */
  889. function locale_css_alter(&$css) {
  890. global $language;
  891. // If the current language is RTL, add the CSS file with the RTL overrides.
  892. if ($language->direction == LANGUAGE_RTL) {
  893. foreach ($css as $data => $item) {
  894. // Only provide RTL overrides for files.
  895. if ($item['type'] == 'file') {
  896. $rtl_path = str_replace('.css', '-rtl.css', $item['data']);
  897. if (file_exists($rtl_path) && !isset($css[$rtl_path])) {
  898. // Replicate the same item, but with the RTL path and a little larger
  899. // weight so that it appears directly after the original CSS file.
  900. $item['data'] = $rtl_path;
  901. $item['weight'] += 0.0001;
  902. $css[$rtl_path] = $item;
  903. }
  904. }
  905. }
  906. }
  907. }
  908. /**
  909. * Implement hook_library_alter().
  910. *
  911. * Provides the language support for the jQuery UI Date Picker.
  912. */
  913. function locale_library_alter(&$libraries, $module) {
  914. if ($module == 'system' && isset($libraries['ui.datepicker'])) {
  915. global $language;
  916. // locale.datepicker.js should be added in the JS_LIBRARY group, so that
  917. // this attach behavior will execute early. JS_LIBRARY is the default for
  918. // hook_library_info_alter(), thus does not have to be specified explicitly.
  919. $datepicker = drupal_get_path('module', 'locale') . '/locale.datepicker.js';
  920. $libraries['ui.datepicker']['js'][$datepicker] = array();
  921. $libraries['ui.datepicker']['js'][] = array(
  922. 'data' => array(
  923. 'jquery' => array(
  924. 'ui' => array(
  925. 'datepicker' => array(
  926. 'isRTL' => $language->direction == LANGUAGE_RTL,
  927. 'firstDay' => variable_get('date_first_day', 0),
  928. ),
  929. ),
  930. ),
  931. ),
  932. 'type' => 'setting',
  933. );
  934. }
  935. }
  936. // ---------------------------------------------------------------------------------
  937. // Language switcher block
  938. /**
  939. * Implements hook_block_info().
  940. */
  941. function locale_block_info() {
  942. include_once DRUPAL_ROOT . '/includes/language.inc';
  943. $block = array();
  944. $info = language_types_info();
  945. foreach (language_types_configurable(FALSE) as $type) {
  946. $block[$type] = array(
  947. 'info' => t('Language switcher (@type)', array('@type' => $info[$type]['name'])),
  948. // Not worth caching.
  949. 'cache' => DRUPAL_NO_CACHE,
  950. );
  951. }
  952. return $block;
  953. }
  954. /**
  955. * Implements hook_block_view().
  956. *
  957. * Displays a language switcher. Only show if we have at least two languages.
  958. */
  959. function locale_block_view($type) {
  960. if (drupal_multilingual()) {
  961. $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
  962. $links = language_negotiation_get_switch_links($type, $path);
  963. if (isset($links->links)) {
  964. drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
  965. $class = "language-switcher-{$links->provider}";
  966. $variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
  967. $block['content'] = theme('links__locale_block', $variables);
  968. $block['subject'] = t('Languages');
  969. return $block;
  970. }
  971. }
  972. }
  973. /**
  974. * Implements hook_url_outbound_alter().
  975. *
  976. * Rewrite outbound URLs with language based prefixes.
  977. */
  978. function locale_url_outbound_alter(&$path, &$options, $original_path) {
  979. // Only modify internal URLs.
  980. if (!$options['external'] && drupal_multilingual()) {
  981. static $drupal_static_fast;
  982. if (!isset($drupal_static_fast)) {
  983. $drupal_static_fast['callbacks'] = &drupal_static(__FUNCTION__);
  984. }
  985. $callbacks = &$drupal_static_fast['callbacks'];
  986. if (!isset($callbacks)) {
  987. $callbacks = array();
  988. include_once DRUPAL_ROOT . '/includes/language.inc';
  989. foreach (language_types_configurable() as $type) {
  990. // Get URL rewriter callbacks only from enabled language providers.
  991. $negotiation = variable_get("language_negotiation_$type", array());
  992. foreach ($negotiation as $id => $provider) {
  993. if (isset($provider['callbacks']['url_rewrite'])) {
  994. if (isset($provider['file'])) {
  995. require_once DRUPAL_ROOT . '/' . $provider['file'];
  996. }
  997. // Avoid duplicate callback entries.
  998. $callbacks[$provider['callbacks']['url_rewrite']] = TRUE;
  999. }
  1000. }
  1001. }
  1002. $callbacks = array_keys($callbacks);
  1003. }
  1004. foreach ($callbacks as $callback) {
  1005. $callback($path, $options);
  1006. }
  1007. // No language dependent path allowed in this mode.
  1008. if (empty($callbacks)) {
  1009. unset($options['language']);
  1010. }
  1011. }
  1012. }