-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-potter.php
111 lines (95 loc) · 2.66 KB
/
class-potter.php
1
2
3
4
5
6
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
50
51
52
53
54
55
56
57
58
59
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Class Potter
* @package oik-i18n
* @copyright (C) Bobbing Wide 2020
*/
class Potter {
public $pot_filename;
public $source_filename;
public $project;
function __construct() {
}
function set_pot_filename( $filename ) {
$this->pot_filename = $filename;
}
function set_project( $project ) {
$this->project = $project;
}
function write_strings( $strings ) {
$output = '';
foreach ( $strings as $string => $filename ) {
$output .= $this->write_fileline( $filename );
$output .= $this->write_string( $string );
$output .= $this->write_blank();
}
return $output;
}
function write_fileline( $filename ) {
$output = '#: ' . $filename;
$output .= PHP_EOL;
return $output;
}
/**
* Writes the string.
*
* Double quotes have to be escaped but not single.
* What about new lines in the middle of the content?
*
* @param $string
* @return string
*/
function write_string( $string ) {
$string = str_replace( '"', '\"', $string );
$output = 'msgid "' . $string . '"';
$output .= PHP_EOL;
$output .= 'msgstr ""';
return $output;
}
function write_blank() {
$output = PHP_EOL;
$output .= '';
$output .= PHP_EOL;
return $output;
}
function write_header() {
$output = [];
$output[] = '# Copyright (C) 2020';
$output[] = '# This file is distributed under the same licence as WordPress';
$output[] = $this->write_string('');
$output[] = "\"Project-Id-Version: {$this->project}\\n\"";
$output[] = "\"Report-Msgid-Bugs-To: http://wordpress.org/tag/{$this->project}\\n\"";
$output[] = "\"POT-Creation-Date: ". date('Y-m-d h:i:s') ."+00:00\\n\"";
$output[] = "\"MIME-Version: 1.0\\n\"";
$output[] = "\"Content-Type: text/plain; charset=UTF-8\\n\"";
$output[] = "\"Content-Transfer-Encoding: 8bit\\n\"";
$output[] = "\"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\\n\"";
$output[] = "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"";
$output[] = "\"Language-Team: LANGUAGE <LL@li.org>\\n\"";
$output[] = '';
$output = implode( PHP_EOL, $output);
$output .= PHP_EOL;
return $output;
}
}
/*
# Copyright (C) 2020 oik
# This file is distributed under the same license as the oik package.
msgid ""
msgstr ""
"Project-Id-Version: oik 4.1.0\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/oik\n"
"POT-Creation-Date: 2020-09-04 13:46:15+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
#: admin/class-bw-list-table.php:153
msgid "List View"
msgstr ""
#: admin/class-bw-list-table.php:154
msgid "Excerpt View"
msgstr ""
*/