Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
use custom gettext call to allow string variables
Browse files Browse the repository at this point in the history
  • Loading branch information
victorstanciu committed Dec 12, 2012
1 parent 9eaa216 commit 1601912
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 35 deletions.
23 changes: 13 additions & 10 deletions DBV.php
Expand Up @@ -109,7 +109,7 @@ public function schemaAction()

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

foreach ($items as $item) {
Expand Down Expand Up @@ -157,7 +157,7 @@ public function revisionsAction()
if ($revision > $current_revision) {
$this->_setCurrentRevision($revision);
}
$this->confirm("Executed revision <strong>$revision</strong>");
$this->confirm(__("Executed revision #{revision}", array('revision' => "<strong>$revision</strong>")));
}
}

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

Expand All @@ -197,11 +197,11 @@ public function saveRevisionFileAction()

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

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

protected function _createSchemaObject($item)
Expand All @@ -210,10 +210,13 @@ protected function _createSchemaObject($item)

if (file_exists($file)) {
if ($this->_runFile($file)) {
$this->confirm("Created schema object <strong>$item</strong>");
$this->confirm(__("Created schema object #{item}", array('item' => "<strong>$item</strong>")));
}
} else {
$this->error("Cannot find file for schema object <strong>$item</strong> (looked in " . DBV_SCHEMA_PATH . ")");
$this->error(__("Cannot find file for schema object #{item} (looked in #{schema_path})", array(
'item' => "<strong>$item</strong>",
'schema_path' => DBV_SCHEMA_PATH
)));
}
}

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

if (@file_put_contents($file, $sql)) {
$this->confirm("Wrote file: <strong>$file</strong>");
$this->confirm(__("Wrote file: #{file}", array('file' => "<strong>$file</strong>")));
} else {
$this->error("Cannot write file: <strong>$file</strong>");
$this->error(__("Cannot write file: #{file}", array('file' => "<strong>$file</strong>")));
}
} catch (DBV_Exception $e) {
$this->error(($e->getCode() ? "[{$e->getCode()}] " : '') . $e->getMessage());
Expand All @@ -242,7 +245,7 @@ protected function _runFile($file)
case 'sql':
$content = file_get_contents($file);
if ($content === false) {
$this->error("Cannot open file <strong>$file</strong>");
$this->error(__("Cannot open file #{file}", array('file' => "<strong>$file</strong>")));
return false;
}

Expand Down
Empty file modified data/meta/revision 100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions index.php
@@ -1,6 +1,7 @@
<?php

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib/functions.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DBV.php';

$dbv = DBV::instance();
Expand Down
13 changes: 13 additions & 0 deletions lib/functions.php
@@ -0,0 +1,13 @@
<?php

function __($message, $params = array())
{
$return = gettext($message);
if (count($params)) {
foreach ($params as $key => $value) {
$return = str_replace("#{" . $key . "}", $value, $return);
}
}

return $return;
}
6 changes: 3 additions & 3 deletions templates/index.php
Expand Up @@ -9,7 +9,7 @@

<link rel="stylesheet" type="text/css" media="screen" href="public/stylesheets/dbv.css" />
<link rel="stylesheet" type="text/css" media="screen" href="public/stylesheets/codemirror.css" />

<script type="text/javascript">
var APP = {};
</script>
Expand All @@ -30,10 +30,10 @@
<div class="container">
<a href="index.php" class="brand">dbv<span>.php</span></a>
<ul class="nav pull-right">
<li><a href="http://dbv.vizuina.com"><?php echo _('Check for updates'); ?></a></li>
<li><a href="http://dbv.vizuina.com"><?php echo __('Check for updates'); ?></a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="content" class="container">
<div id="log" style="margin: 20px 0 -10px 0;">
Expand Down
20 changes: 11 additions & 9 deletions templates/revisions.php
@@ -1,4 +1,4 @@
<h2>Revisions</h2>
<h2><?php echo __('Revisions'); ?></h2>
<?php if (isset($this->revisions) && count($this->revisions)) { ?>
<form method="post" action="" class="nomargin" id="revisions">
<div class="log"></div>
Expand All @@ -7,7 +7,7 @@
<thead>
<tr>
<th style="width: 13px;"><input type="checkbox" style="margin-top: 0;" /></th>
<th><?php echo _('Revision ID'); ?></th>
<th><?php echo __('Revision ID'); ?></th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -35,14 +35,14 @@
<?php $i = 0; ?>
<?php foreach ($files as $file) { ?>
<?php
$extension = pathinfo($file, PATHINFO_EXTENSION);
$extension = pathinfo($file, PATHINFO_EXTENSION);
$content = htmlentities($this->_getRevisionFileContents($revision, $file), ENT_QUOTES, 'UTF-8');
$lines = substr_count($content, "\n");
?>
<div id="revision-file-<?php echo $revision; ?>-<?php echo ++$i; ?>">
<div class="log"></div>
<div class="alert alert-info heading">
<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>
<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>
<strong class="alert-heading"><?php echo $file; ?></strong>
</div>
<textarea data-role="editor" name="revision_files[<?php echo $revision; ?>][<?php echo $file; ?>]" rows="<?php echo $lines + 1; ?>"><?php echo $content; ?></textarea>
Expand All @@ -58,7 +58,9 @@
<input type="submit" class="btn btn-primary" value="Run selected revisions" />
</form>
<?php } else { ?>
<div class="alert alert-info nomargin">No revisions in <strong><?php echo REVISIONS_PATH; ?></strong></div>
<div class="alert alert-info nomargin">
<?php echo __('No revisions in #{path}', array('path' => '<strong>' . REVISIONS_PATH . '</strong>')) ?>
</div>
<?php } ?>
<script type="text/javascript">
document.observe('dom:loaded', function () {
Expand Down Expand Up @@ -115,7 +117,7 @@
},
onSuccess: function (transport) {
self.enable();

var response = transport.responseText.evalJSON();

if (response.error) {
Expand All @@ -135,7 +137,7 @@
clear_messages(this);

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

if (response.messages.error) {
render_messages('error', 'revisions', response.messages.error, '<?php echo _('The following errors occured:'); ?>');
render_messages('error', 'revisions', response.messages.error, '<?php echo __('The following errors occured:'); ?>');
}

if (response.messages.success) {
render_messages('success', 'revisions', response.messages.success, '<?php echo _('The following actions completed successfuly:'); ?>');
render_messages('success', 'revisions', response.messages.success, '<?php echo __('The following actions completed successfuly:'); ?>');
}

var revision = parseInt(response.revision);
Expand Down
26 changes: 13 additions & 13 deletions templates/schema.php
Expand Up @@ -5,7 +5,7 @@
}
?>

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

<?php if (isset($this->schema) && count($this->schema)) { ?>
Expand All @@ -15,8 +15,8 @@
<tr>
<th style="width: 13px;"><input type="checkbox" style="margin-top: 0;" /></th>
<th><?php echo _('Schema object'); ?></th>
<th style="text-align: center; width: 50px;"><?php echo _('In DB'); ?></th>
<th style="text-align: center; width: 50px;"><?php echo _('On disk'); ?></th>
<th style="text-align: center; width: 50px;"><?php echo __('In DB'); ?></th>
<th style="text-align: center; width: 50px;"><?php echo __('On disk'); ?></th>
</tr>
</thead>
<tbody>
Expand All @@ -32,25 +32,25 @@
</td>
<td style="text-align: center;" data-role="database">
<?php if (isset($flags['database'])) { ?>
<span class="label label-success"><?php echo _('YES'); ?></span>
<span class="label label-success"><?php echo __('YES'); ?></span>
<?php } else { ?>
<span class="label label-important"><?php echo _('NO'); ?></span>
<span class="label label-important"><?php echo __('NO'); ?></span>
<?php } ?>
</td>
<td style="text-align: center;" data-role="disk">
<?php if (isset($flags['disk'])) { ?>
<span class="label label-success"><?php echo _('YES'); ?></span>
<span class="label label-success"><?php echo __('YES'); ?></span>
<?php } else { ?>
<span class="label label-important"><?php echo _('NO'); ?></span>
<span class="label label-important"><?php echo __('NO'); ?></span>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>

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

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

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

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

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

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

0 comments on commit 1601912

Please sign in to comment.