Skip to content
Snippets Groups Projects
Commit f1062846 authored by Peter Rotich's avatar Peter Rotich Committed by GitHub
Browse files

Merge pull request #3000 from greezybacon/feature/i18n-version-langpack


I18n language pack versioning

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 298b61ef ba986e11
No related branches found
No related tags found
No related merge requests found
...@@ -550,7 +550,10 @@ abstract class Plugin { ...@@ -550,7 +550,10 @@ abstract class Plugin {
$P = new Phar($phar); $P = new Phar($phar);
$sig = $P->getSignature(); $sig = $P->getSignature();
$info = array(); $info = array();
if ($r = dns_get_record($sig['hash'].'.'.self::$verify_domain, DNS_TXT)) { $ignored = null;
if ($r = dns_get_record($sig['hash'].'.'.self::$verify_domain.'.',
DNS_TXT, $ignored, $ignored, true)
) {
foreach ($r as $rec) { foreach ($r as $rec) {
foreach (explode(';', $rec['txt']) as $kv) { foreach (explode(';', $rec['txt']) as $kv) {
list($k, $v) = explode('=', trim($kv)); list($k, $v) = explode('=', trim($kv));
......
...@@ -40,6 +40,12 @@ class i18n_Compiler extends Module { ...@@ -40,6 +40,12 @@ class i18n_Compiler extends Module {
'help' => 'Add a domain to the path/context of PO strings'), 'help' => 'Add a domain to the path/context of PO strings'),
'dns' => array('-d', '--dns', 'default' => false, 'metavar' => 'zone-id', 'dns' => array('-d', '--dns', 'default' => false, 'metavar' => 'zone-id',
'help' => 'Write signature to DNS (via this AWS HostedZoneId)'), 'help' => 'Write signature to DNS (via this AWS HostedZoneId)'),
'zlib' => array('-z', '--zlib', 'default' => false,
'action' => 'store_true', 'help' => 'Compress PHAR with zlib'),
'bzip2' => array('-j', '--bzip2', 'default' => false,
'action' => 'store_true', 'help' => 'Compress PHAR with bzip2'),
'branch' => array('-b', '--branch', 'help' => 'Use a Crowdin branch
(other than the root)'),
); );
var $epilog = "Note: If updating DNS, you will need to set var $epilog = "Note: If updating DNS, you will need to set
...@@ -100,7 +106,7 @@ class i18n_Compiler extends Module { ...@@ -100,7 +106,7 @@ class i18n_Compiler extends Module {
$this->fail('API key is required'); $this->fail('API key is required');
if (!$options['lang']) if (!$options['lang'])
$this->fail('Language code is required. See `list`'); $this->fail('Language code is required. See `list`');
$this->_build($options['lang']); $this->_build($options['lang'], $options);
break; break;
case 'similar': case 'similar':
$this->find_similar($options); $this->find_similar($options);
...@@ -146,7 +152,7 @@ class i18n_Compiler extends Module { ...@@ -146,7 +152,7 @@ class i18n_Compiler extends Module {
} }
} }
function _build($lang) { function _build($lang, $options) {
list($code, $zip) = $this->_request("download/$lang.zip"); list($code, $zip) = $this->_request("download/$lang.zip");
if ($code !== 200) if ($code !== 200)
...@@ -164,19 +170,34 @@ class i18n_Compiler extends Module { ...@@ -164,19 +170,34 @@ class i18n_Compiler extends Module {
@unlink(I18N_DIR."$lang.phar"); @unlink(I18N_DIR."$lang.phar");
$phar = new Phar(I18N_DIR."$lang.phar"); $phar = new Phar(I18N_DIR."$lang.phar");
$phar->startBuffering(); $phar->startBuffering();
if ($options['zlib'])
$phar->compress(Phar::GZ, 'phar');
if ($options['bzip2'])
$phar->compress(Phar::BZ2, 'phar');
$po_file = false; $po_file = false;
$branch = false;
if ($options['branch'])
$branch = trim($options['branch'], '/') . '/';
for ($i=0; $i<$zip->numFiles; $i++) { for ($i=0; $i<$zip->numFiles; $i++) {
$info = $zip->statIndex($i); $info = $zip->statIndex($i);
if ($branch && strpos($info['name'], $branch) !== 0) {
// Skip files not part of the named branch
continue;
}
$contents = $zip->getFromIndex($i); $contents = $zip->getFromIndex($i);
if (!$contents) if (!$contents)
continue; continue;
if (strpos($info['name'], '/messages.po') !== false) { if (fnmatch('*/messages*.po', $info['name']) !== false) {
$po_file = $contents; $po_file = $contents;
// Don't add the PO file as-is to the PHAR file // Don't add the PO file as-is to the PHAR file
continue; continue;
} }
elseif (!$branch && !file_exists(I18N_DIR . 'en_US/' . $info['name'])) {
// Skip files in (other) branches
continue;
}
$phar->addFromString($info['name'], $contents); $phar->addFromString($info['name'], $contents);
} }
...@@ -190,9 +211,9 @@ class i18n_Compiler extends Module { ...@@ -190,9 +211,9 @@ class i18n_Compiler extends Module {
} }
foreach ($langs as $l) { foreach ($langs as $l) {
list($code, $js) = $this->_http_get( list($code, $js) = $this->_http_get(
'http://imperavi.com/webdownload/redactor/lang/?lang=' sprintf('https://imperavi.com/download/redactor/langs/%s/',
.strtolower($l)); strtolower($l)));
if ($code == 200 && ($js != 'File not found')) { if ($code == 200 && strlen($js) > 100) {
$phar->addFromString('js/redactor.js', $js); $phar->addFromString('js/redactor.js', $js);
break; break;
} }
...@@ -277,7 +298,9 @@ class i18n_Compiler extends Module { ...@@ -277,7 +298,9 @@ class i18n_Compiler extends Module {
$po_header = Mail_Parse::splitHeaders($mo['']); $po_header = Mail_Parse::splitHeaders($mo['']);
$info = array( $info = array(
'Build-Date' => date(DATE_RFC822), 'Build-Date' => date(DATE_RFC822),
'Phrases-Version' => $po_header['X-Osticket-Major-Version'],
'Build-Version' => trim(`git describe`), 'Build-Version' => trim(`git describe`),
'Build-Major-Version' => MAJOR_VERSION,
'Language' => $po_header['Language'], 'Language' => $po_header['Language'],
#'Phrases' => #'Phrases' =>
#'Translated' => #'Translated' =>
...@@ -308,6 +331,8 @@ class i18n_Compiler extends Module { ...@@ -308,6 +331,8 @@ class i18n_Compiler extends Module {
if (!function_exists('openssl_get_privatekey')) if (!function_exists('openssl_get_privatekey'))
$this->fail('OpenSSL extension required for signing'); $this->fail('OpenSSL extension required for signing');
if (!$options['pkey'] || !file_exists($options['pkey']))
$this->fail('Signing private key (-P) required');
$private = openssl_get_privatekey( $private = openssl_get_privatekey(
file_get_contents($options['pkey'])); file_get_contents($options['pkey']));
if (!$private) if (!$private)
......
...@@ -171,18 +171,24 @@ if (!$lv) { ?> ...@@ -171,18 +171,24 @@ if (!$lv) { ?>
<?php <?php
foreach (Internationalization::availableLanguages() as $info) { foreach (Internationalization::availableLanguages() as $info) {
$p = $info['path']; $p = $info['path'];
if ($info['phar']) $p = 'phar://' . $p; if ($info['phar'])
if (file_exists($p . '/MANIFEST.php')) { $p = 'phar://' . $p;
$manifest = (include $p . '/MANIFEST.php'); ?> ?>
<h3><strong><?php echo Internationalization::getLanguageDescription($info['code']); ?></strong> <h3><strong><?php echo Internationalization::getLanguageDescription($info['code']); ?></strong>
&mdash; <?php echo $manifest['Language']; ?> &mdash; <?php echo $manifest['Language']; ?>
<?php if ($info['phar']) <?php if ($info['phar'])
Plugin::showVerificationBadge($info['path']); Plugin::showVerificationBadge($info['path']); ?>
?>
</h3> </h3>
<div><?php echo __('Version'); ?>: <?php echo $manifest['Version']; ?>, <div><?php echo sprintf('<code>%s</code> — %s', $info['code'],
<?php echo __('Built'); ?>: <?php echo $manifest['Build-Date']; ?> str_replace(ROOT_DIR, '', $info['path'])); ?>
<?php if (file_exists($p . '/MANIFEST.php')) {
$manifest = (include $p . '/MANIFEST.php'); ?>
<br/> <?php echo __('Version'); ?>: <?php echo $manifest['Version'];
?>, <?php echo sprintf(__('for version %s'),
'v'.($manifest['Phrases-Version'] ?: '1.9')); ?>
<br/> <?php echo __('Built'); ?>: <?php echo $manifest['Build-Date']; ?>
<?php } ?>
</div> </div>
<?php } <?php
} ?> } ?>
</div> </div>
...@@ -2322,7 +2322,9 @@ tr.disabled th { ...@@ -2322,7 +2322,9 @@ tr.disabled th {
} }
.label { .label {
float: right; display: inline-block;
position: relative;
bottom: 1px;
margin-bottom: 4px; margin-bottom: 4px;
font-size: 11px; font-size: 11px;
padding: 0px 7px; padding: 0px 7px;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment