lang.pl 598 Bytes
Newer Older
1 2 3
#!/usr/bin/perl

use Lingua::Identify qw(:language_identification);
4 5 6 7 8 9
use JSON;
use warnings;
use strict;
binmode STDOUT, ":utf8";
binmode STDIN, ":utf8";
use utf8;
10

11
chomp(my $filename = <STDIN>);
12

13 14 15 16 17
# Lets open the given file:
open(my $fh, "<", $filename)
	or die "Can't open < $filename: $!";
my $json = <$fh>;
close $fh;
18

19
# Decode the JSON String
Dominik Hebeler's avatar
Dominik Hebeler committed
20
my $data = JSON->new->utf8->decode($json);
21

22 23 24 25 26 27 28 29 30 31 32
# Wir durchlaufen den Hash:
foreach my $key (keys %{$data}){
	$data->{$key} = langof($data->{$key});
}

$data = encode_json($data);

# Nur noch die temporäre Datei löschen:
unlink($filename);

print $data;