locale.module 3.04 KB
Newer Older
Dries's avatar
   
Dries committed
1
2
<?

Dries's avatar
   
Dries committed
3
4
5
$module = array("help" => "locale_help",
                "admin" => "locale_admin",
                "locale" => "locale_locale");
Dries's avatar
   
Dries committed
6

Dries's avatar
   
Dries committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function locale_help() {
  print "under construction";
}

function locale_delete($id) {
  db_query("DELETE FROM locales WHERE id = '$id'");
}

function locale_save($id, $edit) {
  foreach ($edit as $key=>$value) {
    db_query("UPDATE locales SET $key = '". check_input($value) ."' WHERE id = '$id'");
  }
}

function locale_edit($id) {
  global $languages;
  $result = db_query("SELECT * FROM locales WHERE id = '$id'");
  if ($translation = db_fetch_object($result)) {
    $output .= "<FORM ACTION=\"admin.php?mod=locale\" METHOD=\"post\">\n";
    $output .= "<B>Original string:</B><BR>\n";
    $output .= check_output($translation->string) ."<P>";
    foreach ($languages as $code=>$language) {
      $output .= "<B>$language:</B><BR>";
      $output .= "<INPUT TYPE=\"text\" NAME=\"edit[$code]\" VALUE=\"". check_textfield($translation->$code) ."\"><P>";
    }
    $output .= "<INPUT NAME=\"id\" TYPE=\"hidden\" VALUE=\"$id\">\n";
    $output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save translations\">\n";
    $output .= "</FORM>\n";

    print $output;
  }
}

function locale_languages($translation) {
  global $languages;
  foreach ($languages as $key=>$value) {
    $output .= ($translation->$key) ? "$key " : "<STRIKE>$key</STRIKE> ";
  }
  return $output;
}

function locale_display() {
  $result = db_query("SELECT * FROM locales ORDER BY string");
Dries's avatar
Dries committed
50
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
   
Dries committed
51
  $output .= " <TR><TH>string</TH><TH>languages</TH><TH COLSPAN=\"2\">operations</TH><TR>\n";
Dries's avatar
   
Dries committed
52
  while ($locale = db_fetch_object($result)) {
Dries's avatar
   
Dries committed
53
54
    $languages = locale_languages($locale);
    $output .= " <TR><TD>". check_output($locale->string) ."<BR><SMALL><I>$locale->location</I></SMALL></TD><TD ALIGN=\"center\">$languages</TD><TD><A HREF=\"admin.php?mod=locale&op=edit&id=$locale->id\">edit</A></TD><TD><A HREF=\"admin.php?mod=locale&op=delete&id=$locale->id\">delete</A></TD></TR>";
Dries's avatar
   
Dries committed
55
  }
Dries's avatar
Dries committed
56
57
  $output .= "</TABLE>\n";
  print $output;
Dries's avatar
   
Dries committed
58
59
}

Dries's avatar
   
Dries committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function locale_admin() {
  global $id, $edit, $op;

  print "<SMALL><A HREF=\"admin.php?mod=locale\">overview</A> | <A HREF=\"admin.php?mod=locale&op=help\">help</A></SMALL><HR>\n";

  switch ($op) {
    case "delete":
      locale_delete($id);
      locale_display();
      break;
    case "help":
      locale_help();
      break;
    case "edit":
      locale_edit($id);
      break;
    case "Save translations":
      locale_save($id, $edit);
      // fall through
    default:
      locale_display();
  }
}

function locale($string) {
  global $locale;
Dries's avatar
Dries committed
86
87
88
89
90
  if ($locale) {
    $result = db_query("SELECT id, $locale FROM locales WHERE STRCMP(string, '". addslashes($string) ."') = 0");
    if ($translation = db_fetch_object($result)) $string = ($translation->$locale) ? check_output($translation->$locale) : $string;
    else db_query("INSERT INTO locales (string, location) VALUES ('". addslashes($string) ."', '". check_input(getenv("REQUEST_URI")) ."')");
  }
Dries's avatar
   
Dries committed
91
92
93
94
  return $string;
}

?>