package PO4Moz::Manifest;

use strict;
use PO4Moz::Util;

sub parse {
  my $filename = shift;
  my $contents = shift;

  # And you thought the ContentsRDF was easy
  
  $filename = "manifest";

  my %entries = ("index" => []);
  my $curentry = {"file" => $filename,
                  "comments" => "",
                  "key" => "language"};

  if ($contents =~ /^locale\s+\S+\s+(\S+)\s+jar:\1.jar!/) {
    # sigh "
    $curentry->{"text"} = $1;
    
    $entries{"$filename:language"} = $curentry;
    push @{$entries{"index"}}, "$filename:language";
    $curentry = {};
  }

  return %entries;
}

sub translate {
  my $file = shift;
  my $contents = shift;
  my %entries = @_;
  my $out = "";
  
  # easy too?

  $file = "manifest";
  $out = $contents;
  if ($entries{"$file:language"}) {
    my $text = $entries{"$file:language"}->{"text"};
    my $locale = $entries{"$file:language"}->{"translation"};
    if ($locale) {
      $out =~ s/$text/$locale/sg;
      $out =~ s/jar:.*?!/jar:chrome\/$locale.jar!/sg;
    }
  }
  
  return $out;
}  

1;
