update_translation.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use integer;
  4. use File::Basename;
  5. use File::Find;
  6. use File::Spec;
  7. use Cwd;
  8. my %trstrings;
  9. {
  10. my $dir = getcwd() or die "Don't know which directory to run from: $!\n";
  11. chdir $dir;
  12. find(\&translations, $dir);
  13. my @strings = keys %trstrings;
  14. my $size = @strings;
  15. if ($size > 0)
  16. {
  17. my $modname = &get_current_modname($dir);
  18. my $englishfile = File::Spec->catfile($dir, "locale", "$modname.en.tr");
  19. open my $trtemplate, ">$englishfile" or die "Cannot write to file $englishfile: $!\n";
  20. print $trtemplate "# textdomain:$modname\n";
  21. foreach my $string (sort @strings)
  22. {
  23. print $trtemplate "$string=$string\n";
  24. }
  25. close $trtemplate;
  26. }
  27. }
  28. sub translations()
  29. {
  30. if (-T $_)
  31. {
  32. if (m/\.lua/)
  33. {
  34. open my $codefile, "<$_";
  35. while (<$codefile>)
  36. {
  37. if (m/S\("(.*?)"\)/)
  38. {
  39. if (defined $1)
  40. {
  41. $trstrings{$1} = 1;
  42. }
  43. }
  44. }
  45. close $codefile;
  46. }
  47. }
  48. }
  49. sub get_current_modname($)
  50. {
  51. my ($dir) = @_;
  52. my $defaultmodname = "modname";
  53. my $modname = $defaultmodname;
  54. my $modconf = File::Spec->catfile($dir, "mod.conf");
  55. if (-T $modconf)
  56. {
  57. open my $modconffile, "<$modconf";
  58. while (<$modconffile>)
  59. {
  60. if (m/name\s*=\s*(\S*)/)
  61. {
  62. if ($1)
  63. {
  64. $modname = $1;
  65. }
  66. }
  67. }
  68. close $modconffile;
  69. }
  70. if ($modname eq $defaultmodname)
  71. {
  72. $modname = basename($dir);
  73. }
  74. return $modname;
  75. }