Skip to content

Commit 1601912

Browse files
committed
use custom gettext call to allow string variables
1 parent 9eaa216 commit 1601912

File tree

7 files changed

+54
-35
lines changed

7 files changed

+54
-35
lines changed

DBV.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function schemaAction()
109109

110110
if ($this->_isXMLHttpRequest()) {
111111
if (!count($items)) {
112-
return $this->_json(array('error' => "You didn't select any objects"));
112+
return $this->_json(array('error' => __("You didn't select any objects")));
113113
}
114114

115115
foreach ($items as $item) {
@@ -157,7 +157,7 @@ public function revisionsAction()
157157
if ($revision > $current_revision) {
158158
$this->_setCurrentRevision($revision);
159159
}
160-
$this->confirm("Executed revision <strong>$revision</strong>");
160+
$this->confirm(__("Executed revision #{revision}", array('revision' => "<strong>$revision</strong>")));
161161
}
162162
}
163163

@@ -184,7 +184,7 @@ public function saveRevisionFileAction()
184184
$file = $_POST['file'];
185185
} else {
186186
$this->_json(array(
187-
'error' => "Filename {$_POST['file']} contains illegal characters. Please contact the developer."
187+
'error' => __("Filename #{file} contains illegal characters. Please contact the developer.", array('file' => $_POST['file']))
188188
));
189189
}
190190

@@ -197,11 +197,11 @@ public function saveRevisionFileAction()
197197

198198
if (!@file_put_contents($path, $content)) {
199199
$this->_json(array(
200-
'error' => "Couldn't write file: <strong>$path</strong><br />Make sure the user running DBV has adequate permissions."
200+
'error' => __("Couldn't write file: #{path}<br />Make sure the user running DBV has adequate permissions.", array('path' => "<strong>$path</strong>"))
201201
));
202202
}
203203

204-
$this->_json(array('ok' => true, 'message' => "File <strong>$path</strong> successfully saved!"));
204+
$this->_json(array('ok' => true, 'message' => __("File #{path} successfully saved!", array('path' => "<strong>$path</strong>"))));
205205
}
206206

207207
protected function _createSchemaObject($item)
@@ -210,10 +210,13 @@ protected function _createSchemaObject($item)
210210

211211
if (file_exists($file)) {
212212
if ($this->_runFile($file)) {
213-
$this->confirm("Created schema object <strong>$item</strong>");
213+
$this->confirm(__("Created schema object #{item}", array('item' => "<strong>$item</strong>")));
214214
}
215215
} else {
216-
$this->error("Cannot find file for schema object <strong>$item</strong> (looked in " . DBV_SCHEMA_PATH . ")");
216+
$this->error(__("Cannot find file for schema object #{item} (looked in #{schema_path})", array(
217+
'item' => "<strong>$item</strong>",
218+
'schema_path' => DBV_SCHEMA_PATH
219+
)));
217220
}
218221
}
219222

@@ -225,9 +228,9 @@ protected function _exportSchemaObject($item)
225228
$file = DBV_SCHEMA_PATH . DS . "$item.sql";
226229

227230
if (@file_put_contents($file, $sql)) {
228-
$this->confirm("Wrote file: <strong>$file</strong>");
231+
$this->confirm(__("Wrote file: #{file}", array('file' => "<strong>$file</strong>")));
229232
} else {
230-
$this->error("Cannot write file: <strong>$file</strong>");
233+
$this->error(__("Cannot write file: #{file}", array('file' => "<strong>$file</strong>")));
231234
}
232235
} catch (DBV_Exception $e) {
233236
$this->error(($e->getCode() ? "[{$e->getCode()}] " : '') . $e->getMessage());
@@ -242,7 +245,7 @@ protected function _runFile($file)
242245
case 'sql':
243246
$content = file_get_contents($file);
244247
if ($content === false) {
245-
$this->error("Cannot open file <strong>$file</strong>");
248+
$this->error(__("Cannot open file #{file}", array('file' => "<strong>$file</strong>")));
246249
return false;
247250
}
248251

data/meta/revision

100644100755
File mode changed.

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.php';
4+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib/functions.php';
45
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DBV.php';
56

67
$dbv = DBV::instance();

lib/functions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
function __($message, $params = array())
4+
{
5+
$return = gettext($message);
6+
if (count($params)) {
7+
foreach ($params as $key => $value) {
8+
$return = str_replace("#{" . $key . "}", $value, $return);
9+
}
10+
}
11+
12+
return $return;
13+
}

templates/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<link rel="stylesheet" type="text/css" media="screen" href="public/stylesheets/dbv.css" />
1111
<link rel="stylesheet" type="text/css" media="screen" href="public/stylesheets/codemirror.css" />
12-
12+
1313
<script type="text/javascript">
1414
var APP = {};
1515
</script>
@@ -30,10 +30,10 @@
3030
<div class="container">
3131
<a href="index.php" class="brand">dbv<span>.php</span></a>
3232
<ul class="nav pull-right">
33-
<li><a href="http://dbv.vizuina.com"><?php echo _('Check for updates'); ?></a></li>
33+
<li><a href="http://dbv.vizuina.com"><?php echo __('Check for updates'); ?></a></li>
3434
</ul>
3535
</div>
36-
</div>
36+
</div>
3737
</div>
3838
<div id="content" class="container">
3939
<div id="log" style="margin: 20px 0 -10px 0;">

templates/revisions.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h2>Revisions</h2>
1+
<h2><?php echo __('Revisions'); ?></h2>
22
<?php if (isset($this->revisions) && count($this->revisions)) { ?>
33
<form method="post" action="" class="nomargin" id="revisions">
44
<div class="log"></div>
@@ -7,7 +7,7 @@
77
<thead>
88
<tr>
99
<th style="width: 13px;"><input type="checkbox" style="margin-top: 0;" /></th>
10-
<th><?php echo _('Revision ID'); ?></th>
10+
<th><?php echo __('Revision ID'); ?></th>
1111
</tr>
1212
</thead>
1313
<tbody>
@@ -35,14 +35,14 @@
3535
<?php $i = 0; ?>
3636
<?php foreach ($files as $file) { ?>
3737
<?php
38-
$extension = pathinfo($file, PATHINFO_EXTENSION);
38+
$extension = pathinfo($file, PATHINFO_EXTENSION);
3939
$content = htmlentities($this->_getRevisionFileContents($revision, $file), ENT_QUOTES, 'UTF-8');
4040
$lines = substr_count($content, "\n");
4141
?>
4242
<div id="revision-file-<?php echo $revision; ?>-<?php echo ++$i; ?>">
4343
<div class="log"></div>
4444
<div class="alert alert-info heading">
45-
<button data-role="editor-save" data-revision="<?php echo $revision; ?>" data-file="<?php echo $file; ?>" type="button" class="btn btn-mini btn-info pull-right" style="margin-top: -1px;">Save file</button>
45+
<button data-role="editor-save" data-revision="<?php echo $revision; ?>" data-file="<?php echo $file; ?>" type="button" class="btn btn-mini btn-info pull-right" style="margin-top: -1px;"><?php echo __('Save file') ?></button>
4646
<strong class="alert-heading"><?php echo $file; ?></strong>
4747
</div>
4848
<textarea data-role="editor" name="revision_files[<?php echo $revision; ?>][<?php echo $file; ?>]" rows="<?php echo $lines + 1; ?>"><?php echo $content; ?></textarea>
@@ -58,7 +58,9 @@
5858
<input type="submit" class="btn btn-primary" value="Run selected revisions" />
5959
</form>
6060
<?php } else { ?>
61-
<div class="alert alert-info nomargin">No revisions in <strong><?php echo REVISIONS_PATH; ?></strong></div>
61+
<div class="alert alert-info nomargin">
62+
<?php echo __('No revisions in #{path}', array('path' => '<strong>' . REVISIONS_PATH . '</strong>')) ?>
63+
</div>
6264
<?php } ?>
6365
<script type="text/javascript">
6466
document.observe('dom:loaded', function () {
@@ -115,7 +117,7 @@
115117
},
116118
onSuccess: function (transport) {
117119
self.enable();
118-
120+
119121
var response = transport.responseText.evalJSON();
120122

121123
if (response.error) {
@@ -135,7 +137,7 @@
135137
clear_messages(this);
136138

137139
if (!data.hasOwnProperty('revisions[]')) {
138-
render_messages('error', this, "You didn't select any revisions to run");
140+
render_messages('error', this, '<?php echo __("You didn\'t select any revisions to run") ?>');
139141
Effect.ScrollTo('log', {duration: 0.2});
140142
return false;
141143
}
@@ -156,11 +158,11 @@
156158
}
157159

158160
if (response.messages.error) {
159-
render_messages('error', 'revisions', response.messages.error, '<?php echo _('The following errors occured:'); ?>');
161+
render_messages('error', 'revisions', response.messages.error, '<?php echo __('The following errors occured:'); ?>');
160162
}
161163

162164
if (response.messages.success) {
163-
render_messages('success', 'revisions', response.messages.success, '<?php echo _('The following actions completed successfuly:'); ?>');
165+
render_messages('success', 'revisions', response.messages.success, '<?php echo __('The following actions completed successfuly:'); ?>');
164166
}
165167

166168
var revision = parseInt(response.revision);

templates/schema.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66
?>
77

8-
<h2><?php echo _('Database schema'); ?></h2>
8+
<h2><?php echo __('Database schema'); ?></h2>
99
<div class="log"></div>
1010

1111
<?php if (isset($this->schema) && count($this->schema)) { ?>
@@ -15,8 +15,8 @@
1515
<tr>
1616
<th style="width: 13px;"><input type="checkbox" style="margin-top: 0;" /></th>
1717
<th><?php echo _('Schema object'); ?></th>
18-
<th style="text-align: center; width: 50px;"><?php echo _('In DB'); ?></th>
19-
<th style="text-align: center; width: 50px;"><?php echo _('On disk'); ?></th>
18+
<th style="text-align: center; width: 50px;"><?php echo __('In DB'); ?></th>
19+
<th style="text-align: center; width: 50px;"><?php echo __('On disk'); ?></th>
2020
</tr>
2121
</thead>
2222
<tbody>
@@ -32,25 +32,25 @@
3232
</td>
3333
<td style="text-align: center;" data-role="database">
3434
<?php if (isset($flags['database'])) { ?>
35-
<span class="label label-success"><?php echo _('YES'); ?></span>
35+
<span class="label label-success"><?php echo __('YES'); ?></span>
3636
<?php } else { ?>
37-
<span class="label label-important"><?php echo _('NO'); ?></span>
37+
<span class="label label-important"><?php echo __('NO'); ?></span>
3838
<?php } ?>
3939
</td>
4040
<td style="text-align: center;" data-role="disk">
4141
<?php if (isset($flags['disk'])) { ?>
42-
<span class="label label-success"><?php echo _('YES'); ?></span>
42+
<span class="label label-success"><?php echo __('YES'); ?></span>
4343
<?php } else { ?>
44-
<span class="label label-important"><?php echo _('NO'); ?></span>
44+
<span class="label label-important"><?php echo __('NO'); ?></span>
4545
<?php } ?>
4646
</td>
4747
</tr>
4848
<?php } ?>
4949
</tbody>
5050
</table>
5151

52-
<button data-role="create" class="btn btn-primary btn-mini"><?php echo _('Push to database'); ?></button>
53-
<button data-role="export" class="btn btn-primary btn-mini"><?php echo _('Export to disk'); ?></button>
52+
<button data-role="create" class="btn btn-primary btn-mini"><?php echo __('Push to database'); ?></button>
53+
<button data-role="export" class="btn btn-primary btn-mini"><?php echo __('Export to disk'); ?></button>
5454
</form>
5555

5656
<script type="text/javascript">
@@ -73,15 +73,15 @@
7373
var response = transport.responseText.evalJSON();
7474

7575
if (typeof response.error != 'undefined') {
76-
return APP.growler.error('<?php echo _('Error!'); ?>', response.error);
76+
return APP.growler.error('<?php echo __('Error!'); ?>', response.error);
7777
}
7878

7979
if (response.messages.error) {
80-
render_messages('error', 'left', response.messages.error, '<?php echo _('The following errors occured:'); ?>');
80+
render_messages('error', 'left', response.messages.error, '<?php echo __('The following errors occured:'); ?>');
8181
}
8282

8383
if (response.messages.success) {
84-
render_messages('success', 'left', response.messages.success, '<?php echo _('The following actions completed successfuly:'); ?>');
84+
render_messages('success', 'left', response.messages.success, '<?php echo __('The following actions completed successfuly:'); ?>');
8585
}
8686

8787
var items = response.items;
@@ -106,5 +106,5 @@
106106
});
107107
</script>
108108
<?php } else { ?>
109-
<div class="alert alert-info nomargin"><?php echo _('No schema objects found on disk or in the database.'); ?></div>
109+
<div class="alert alert-info nomargin"><?php echo __('No schema objects found on disk or in the database.'); ?></div>
110110
<?php } ?>

0 commit comments

Comments
 (0)