Initialize Tizen 2.3
[apps/home/b2-clocksetting.git] / po / replace_quatation.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Tie::File;
6
7 # global
8 my @po_list = `ls *.po`;
9
10 # for replacing "
11 my $dest_char1 = "\\\\\"";
12 my $dest_char2 = "\\\"";
13 my $quatation_char = "\"";
14
15 # function
16 sub replace_quatation
17 {
18     my ($po_file) = @_;
19     my @po_file_line = $po_file;
20
21     foreach (@po_file_line) {
22         tie my @filearray, 'Tie::File', $_ or die "Couldn't open file $_, $!";       
23         foreach my $line(@filearray) {
24             if (($line =~ /msgstr\ \"(.*)\"/)) {
25                 my $new_line = $1;
26
27                 # quatation check
28                 # there is no qutation, continue
29                 if (index($new_line, "\"") != -1) {
30                     printf "replace: $new_line\n";
31                     # equalizing to "
32                     $new_line =~ s/$dest_char1/$quatation_char/g;
33
34                     # replace " with \"
35                     $new_line =~ s/$quatation_char/$dest_char2/g;
36
37                     # write new line
38                     $line = "msgstr\ \"$new_line\"";
39                 }
40             }
41         }
42         untie @filearray;
43     }
44 }
45
46 sub replace_another
47 {
48     my ($po_file) = @_;
49     my @po_file_line = $po_file;
50
51     foreach (@po_file_line) {
52         tie my @filearray, 'Tie::File', $_ or die "Couldn't open file $_, $!";       
53         foreach my $line(@filearray) {
54             if (($line =~ /msgstr\ \"(.*)\"/)) {
55                 my $new_line = $1;
56
57                 if (index($new_line, "\\") != -1) {
58                     printf "replace: $new_line\n";
59
60                     # replace \n with <br> 
61                     $new_line =~ s/\\/ /g;
62
63                     # write new line
64                     $line = "msgstr\ \"$new_line\"";
65                 }
66             }
67         }
68         untie @filearray;
69     }
70 }
71
72 sub replace_br
73 {
74     my ($po_file) = @_;
75     my @po_file_line = $po_file;
76
77     foreach (@po_file_line) {
78         tie my @filearray, 'Tie::File', $_ or die "Couldn't open file $_, $!";       
79         foreach my $line(@filearray) {
80             if (($line =~ /msgstr\ \"(.*)\"/)) {
81                 my $new_line = $1;
82
83                 if (index($new_line, "<br>") != -1) {
84                     printf "replace: $new_line\n";
85
86                     # replace <br> with \n 
87                     $new_line =~ s/<br>/\\n/g;
88
89                     # write new line
90                     $line = "msgstr\ \"$new_line\"";
91                 }
92             }
93         }
94         untie @filearray;
95     }
96 }
97
98 sub replace_driver_str
99 {
100     my ($po_file) = @_;
101     my @po_file_line = $po_file;
102
103     foreach (@po_file_line) {
104         tie my @filearray, 'Tie::File', $_ or die "Couldn't open file $_, $!";       
105         foreach my $line(@filearray) {
106             if (($line =~ /msgstr\ \"(.*)\"/)) {
107                 my $new_line = $1;
108
109                 if (index($new_line, ":\\") != -1) {
110                     printf "replace: $new_line\n";
111
112                     if( index($new_line, ":\\\\") == -1 ) {
113                         # replace <br> with \n 
114                         $new_line =~ s/:\\/:\\\\/g;
115
116                         # write new line
117                         $line = "msgstr\ \"$new_line\"";
118                     }
119                 }
120             }
121         }
122         untie @filearray;
123     }
124 }
125
126 # main
127 foreach (@po_list) {
128     my $file = $_;
129     chomp($file);
130     replace_quatation($file);
131     replace_driver_str($file);
132     #replace_another($file);
133 }