gmap.strings.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * gmap.strings.php
  5. * PURPOSE
  6. *
  7. * This is a stand-alone script which
  8. * takes markers titles and wraps them in t()'s.
  9. * The reason we want to do this is because variables
  10. * can not be passed through t() with .pot files generated
  11. * by the potx module.
  12. *
  13. * The result of running this script should be the creation
  14. * of a file in the root of the gmap module's directory, called
  15. * 'gmap.strings.inc', containing a function 'gmap_marker_labels'
  16. * which returns an array holding each of the marker labels wrapped in t().
  17. *
  18. * INSTALLATION
  19. *
  20. * This script needs to be run within drupal, so the best way
  21. * to accomplish this is to install and enable the devel module, then,
  22. * enable the 'Execute PHP' block somewhere.
  23. *
  24. * Then, just paste this script into the text field in the Execute PHP block,
  25. * and click 'Execute'!
  26. * This will create the gmap.strings.inc file in the gmap module's directory -
  27. * be sure to adjust the permissions of this new file appropriately!
  28. */
  29. $markerdir = variable_get('gmap_markerfiles', drupal_get_path('module', 'gmap') . '/markers');
  30. // The following routines are designed to be easy to comprehend, not fast.
  31. // This whole process gets cached.
  32. // Get the ini files.
  33. $inifiles = file_scan_directory($markerdir, '.*\.ini$');
  34. $labels = array();
  35. foreach ($inifiles as $file) {
  36. $icon_data = parse_ini_file($file->filename, TRUE);
  37. foreach ($icon_data as $icon_set) {
  38. if (isset($icon_set['name'])) {
  39. $marker_labels[] = "t('" . $icon_set['name'] . "'),";
  40. }
  41. }
  42. }
  43. // Create a .inc file for our info.
  44. $gmap_strings_inc_name = drupal_get_path('module', 'gmap') . '/gmap.strings.inc';
  45. // Open our file.
  46. $gmap_strings_inc_handle = fopen($gmap_strings_inc_name, 'w');
  47. // Format the data.
  48. $label_container = '';
  49. $label_container .= "<?php\n\nfunction gmap_marker_labels_potx() {\n";
  50. $label_container .= "\$marker_labels = array(\n";
  51. foreach ($marker_labels as $label_key => $label) {
  52. $label_container .= "$label_key";
  53. $label_container .= ' => ';
  54. $label_container .= "$label";
  55. $label_container .= "\n";
  56. }
  57. $label_container .= ')';
  58. $label_container .= ";\n";
  59. $label_container .= "return \$marker_labels\n";
  60. $label_container .= '}';
  61. // Write file.
  62. if (fwrite($gmap_strings_inc_handle, $label_container) !== 'FALSE') {
  63. drupal_set_message(t('File gmap_strings.inc successfully created.'));
  64. }