Subversion Repositories wimsdev

Rev

Rev 6970 | Rev 8425 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/usr/bin/perl
  2.  
  3. # From the distribution files
  4. # domain : structured list of all (sub)domains (words containing underscores)
  5. # domain.xx : list of correspondance between domain names and their translation (spaces allowed) in language xx.
  6. # this script constructs the following files
  7. # reversedomain  : list of parents of each domain
  8. # domain.json    : list of domains up to third level
  9. # domain.xx.json : sorted list of translations of domain names (without domain_name itself)
  10. # domain.xx.tmp  : should be (not checked) domains of file domain for which a translation exists in domain.xx.
  11. ##                 In practice it is (not checked) same as domain.xx,
  12. ##                 with empty translation replaced by left member (= domain_name) of record
  13. ##                 and completed with domains appearing in domain but not in domain.xx.
  14. ##                 This is also sorted.
  15. # domaindic.xx.tmp   : dictionnary for modind
  16. use warnings;
  17. use strict;
  18. use search ('hashdomain', 'listdomain', 'out', 'sortuniq', 'treate_dict', 'treate_language','treate_accent');
  19.  
  20. my $dir='domain';
  21. my @site_lang= treate_language ();
  22. $/ = undef;
  23.  
  24. ## Make sorted list of all domains in domain/domain
  25. my @list=listdomain("$dir/domain");
  26.  
  27. ## For translators : make a domain.template as a base for domain.xx file
  28. ## Helpful for creation of new language or to check for completeness of current domain.xx file
  29. #my $text=join(":\n", @list) . ":\n";
  30. #$text=~ s/^://g;
  31. #$text=~ s/ +\n/\n/g;
  32. #out("$dir/domain.template", $text);
  33.  
  34. ## Put in domain/reversedomain the list of parents of each domain.
  35. my %ref= hashdomain("$dir/domain");
  36. my $ref=\%ref;
  37. my $TEXT="##generated\n";
  38. for my $tag (keys %ref) {
  39.   $TEXT .= "$tag:$ref{$tag}\n" ;
  40. }
  41.  
  42. out("$dir/reversedomain",$TEXT);
  43.  
  44. ## Put in domain/domain.json the sorted list of domains up to third level
  45. out("$dir/domain.json", domainjson(%ref));
  46.  
  47. ## for languages for which domain.xx exists, construct files
  48. ## domain.xx.tmp : sorted list of domains names and their translation, approximately union of domain and domain.xx
  49. ## domain.xx.json : sorted list of translations of domain names (without domain_name itself)
  50. for my $la ( @site_lang) {
  51.  next if !(-e "$dir/domain.$la");
  52.  my %dom = treate_dict ("$dir/domain.$la");
  53.  my $dom = \%dom;
  54.   for my $a (@list) {
  55.   if (!$dom{$a}) { $dom{$a} = '' ; }
  56.  };
  57.  my @D=();
  58.  my @D_lang=();
  59.  my @D_reverse=();
  60.  while ( my ($key, $value) = each(%dom) ) {
  61.    push @D, "$key:$value";
  62.    $key=~ s/_/ /g;
  63.    if ($value) {
  64.      ##push @D_reverse, lc(treate_accent($value)) . ":$key|" . lc(treate_accent($value));
  65.      push @D_reverse, lc(treate_accent($value)) . ":$key";
  66.    }
  67.    $value=~ s/'/ /g;
  68.    push @D_lang, lc($value);
  69.  };
  70.  out("$dir/domain.$la.tmp", join("\n",sortuniq(@D)) . "\n");
  71.  out("$dir/domaindic.$la.tmp", join("\n",sortuniq(@D_reverse)) . "\n");
  72.  out("$dir/domain.$la.json", "\"" . join("\",\n\"",sortuniq(@D_lang)) . "\"");
  73. }
  74.  
  75. #####################################################
  76. sub domainjson { my ($ref) = @_ ;
  77.   my @D=();
  78.   while ( my ($key, $value) = each(%ref) ) {
  79.     if ( $value =~ /domain\b/ ) { push @D, $key }
  80.     else {
  81.       if ($ref{$value}) {
  82.        if ($ref{$value} =~ /domain\b/) { push @D, $key }
  83.          else {
  84.              if ($ref{$ref{$value}}) {
  85.                if($ref{$ref{$value}} =~ /domain\b/) { push @D, $key; }
  86.                }
  87.            }
  88.        };
  89.      };
  90.    }
  91. "<!-- generated -->\n['" . join("',\n'", sortuniq(@D)) . "']";
  92. }
  93.