Skip to content

Commit

Permalink
Merge pull request #12 from leotiger/develop
Browse files Browse the repository at this point in the history
merge latest develop into master
  • Loading branch information
leotiger authored Aug 10, 2018
2 parents b73fef8 + dcc1dfa commit 8f518eb
Show file tree
Hide file tree
Showing 142 changed files with 224 additions and 25,715 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# v1.1.2
## 10-08-2018

1. [](#improved)
* Add quicktray icon and make entry in admin menu sidebar optional (thx olevik)
* remove unnecessary logging code
* add hints to the interface
* apply GRAV styles to some elements
* remove bootstrap css
* better documentation in README
1. [](#bugfix)
* Copy correct existing translation into empty translation if user click on language identifier of existing translation
* Fix compatibility issue: TNTSearch uses an older vendor version of the teamtnt/tntsearch (thx iusvar)


# v1.1.1
## 09-08-2018

1. [](#new)
* Track theme variables
* Add export for theme language packages
1. [](#bugfix)
* Fix order of flat array elements with numeric keys.
* Display flat array elements in correct order (keys ordered alphabetically and not numerically)
Expand Down
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,38 @@ With the advent of the Babel plugin this changes a bit.
## Usage

To use the plugin you have to enable language support for you GRAV instance and you have to configure as well the languages you want to
handle with Babel in the plugin configuration. The languages handled by Babel do not have to be identical with the languages enabled for your
handle with Babel in the configuration of the Babel plugin. The languages handled by Babel do not have to be identical with the languages enabled for your
instance. This allows you to prepare additional languages before activating new ones for your site.

Once you have enabled the Babel languages you can index all language variables and existing translations. There is one magic keyboard shortcut
available Command/Ctrl + s which allows you to save right from within of the textarea field used to edit translations.
You can access Babel using the dedicated tray icon or by using the link in the plugin configuration. If you use Babel frequently you may activate a permanent Admin menu link
to Babel.

Babel identifies edited and merged definitions when a re-index takes place. This allows the plugin to only merge edited definitions.
On first time load of the Babel administration page, you will be asked to create an index. Once the index is created, you will see a breakdown
table informing about the general status of translated and untranslated variables and you may filter this data using the domain filter selector.

Important: Please merge your changes. Without merging changes are lost once you re-index.
If there are defined, translated or untranslated items in a given context (language, domain) available you can load the translations using the
blue buttons in the corresponding rows of the breakdown table.

You can export language packs based on domains, e.g. export translations sets related with PLUGIN_ADMIN. The language pack includes all exported
definitions. Please take into account that you have to trigger the export for each language. Export functionality is only available when a language domain
is active but not for all domains and not for the *babelized* filter. From version 1.1.1 onwards you can export as well theme language packages.
Once you've loaded a list of language variables you can edit translations for a given language. Inside of the textarea you can use Ctrl+s or
Command+s to save your edited translation. If the translation is empty you can copy existing translations in other languages into the empty field by
clicking on the language shortcode in the right column next to the translation editor.

The plugin offers three special filters that represent virtual domains:
To load the changed translations in your current instance, you have to merge them using the Merge button.

* all domains
* babelized (items edited with the Babel plugin)
* unclassified
If you load a language domain via a selection option of the filter, e.g. PLUGIN_BABEL or THEME_TRACKED you are presented with an additional option
in the translation breakdown table: the export button. The export button allows you to export and download translation packages. If you don't see
your translation package in the bottom region of the page after running an export, please reload the page.

To reset the system, you can use the Reset button. The reset will remove the Babel edit flag and recover the original definitions. You have to confirm this
operation with a new merge. The merge routine, if it does not detect entries changed with Babel, removes existing merge files from the instance.

The last filter loads a collection of variables that are directly attached to the root without a parent domain scope.

## What's missing

* a common, shared language repository for GRAV
* a common, shared language repository for GRAV, Babel will probably integrate this using the Crowdin platform, already used for GRAV and the GRAV
Admin plugin
* integration with the language repository
* automatic detection of new variables after upgrades of GRAV, plugins and themes (you can nevertheless always re-index manually)
* Bit of code cleanup and less dependencies (bootstrap 3, datatables-net)
* Mark translations as private allowing for alternative public value

## Installation
Expand Down
73 changes: 54 additions & 19 deletions admin/templates/babel_domains.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@
text-align: center;
}
</style>

<div class="index-status">
{% if babel_index_status.status %}
<button id="babel-index" class="button reindex babel-reindex">{{ "PLUGIN_BABEL.REINDEX"|tu }}</button>
<button id="babel-index" class="button reindex babel-reindex hint--bottom" data-hint="{{ "PLUGIN_BABEL.REINDEX_HINT"|t|e('html_attr') }}">{{ "PLUGIN_BABEL.REINDEX"|tu }}</button>
<span class="babel-status success"><i class="fa fa-language"></i> {{ babel_index_status.msg }}</span>
{% else %}
<button id="babel-index" class="button critical babel-reindex">{{ "PLUGIN_BABEL.INDEX"|tu }}</button>
<button id="babel-index" class="button critical babel-reindex hint--bottom" data-hint="{{ "PLUGIN_BABEL.INDEX_HINT"|t|e('html_attr') }}">{{ "PLUGIN_BABEL.INDEX"|tu }}</button>
<span class="babel-status error"><i class="fa fa-warning"></i> {{ babel_index_status.msg }}</span>
{% endif %}
{% if babelstats %}
<button id="babel-reset" class="button reset babel-reset">{{ "PLUGIN_BABEL.RESET"|tu }}</button>
<button id="babel-merge" class="button merge babel-merge">{{ "PLUGIN_BABEL.MERGE"|tu }}</button>
<button id="babel-reset" class="button reset babel-reset hint--bottom" data-hint="{{ "PLUGIN_BABEL.RESET_HINT"|t|e('html_attr') }}">{{ "PLUGIN_BABEL.RESET"|tu }}</button>
<button id="babel-merge" class="button merge babel-merge hint--bottom" data-hint="{{ "PLUGIN_BABEL.MERGE_HINT"|t|e('html_attr') }}">{{ "PLUGIN_BABEL.MERGE"|tu }}</button>
{% endif %}
<div class="warning babel-error-details"></div>
<div class="intro-hint">
{{ "PLUGIN_BABEL.INTRO_HINT"|tu }}
</div>
</div>


Expand All @@ -34,23 +38,45 @@
<!--<input type="text" placeholder="{{ "PLUGIN_BABEL.SEARCH"|t|e }}" />
<br />-->
{% if babelstats %}
<select id="babeldomains" data-domainfiles="{{ domainfiles|json_encode() }}">
<div class="form-select form-select-wrapper large">
<label>
<span class="data--hint" data-hint="{{ "PLUGIN_BABEL.DOMAIN_FILTER_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.DOMAIN_FILTER"|tu }}
</span>
</label>
<select id="babeldomains" data-domainfiles="{{ domainfiles|json_encode() }}" data-grav-selectize style="vertical selectize">
<option value="*" {{ current_domain == '*' ? 'selected="selected"' : '' }}>{{ "PLUGIN_BABEL.ALL_DOMAINS"|tu }}</option>
<option value="*b" {{ current_domain == '*b' ? 'selected="selected"' : '' }}>{{ "PLUGIN_BABEL.BABEL_TOUCHED"|tu }}</option>
{% for domain in domains %}
<option value="{{ domain }}" {{ current_domain == domain ? 'selected="selected"' : '' }}>{{ domain }}</option>
{% endfor %}
</select>
</select>
</div>
<table>
<thead>
<tr>
<th>{{ "PLUGIN_BABEL.TRANSLATION_SET"|tu }}</th>
<!--<th>{{ "PLUGIN_BABEL.DOMAIN"|tu }}</th>-->
<th>{{ "PLUGIN_BABEL.DEFINED"|tu }}</th>
<th>{{ "PLUGIN_BABEL.TRANSLATED"|tu }}</th>
<th>{{ "PLUGIN_BABEL.UNTRANSLATED"|tu }}</th>
<th>
<span class="hint--bottom" data-hint="{{ "PLUGIN_BABEL.STATS_COLUMN_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.DEFINED"|tu }}
</span>
</th>
<th>
<span class="data--hint" data-hint="{{ "PLUGIN_BABEL.STATS_COLUMN_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.TRANSLATED"|tu }}
</span>
</th>
<th>
<span class="hint--bottom" data-hint="{{ "PLUGIN_BABEL.STATS_COLUMN_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.UNTRANSLATED"|tu }}
</span>
</th>
<th>{{ "PLUGIN_BABEL.RATIO"|tu }}</th>
<th>{{ "PLUGIN_BABEL.EXPORT"|tu }}</th>
<th>
<span class="hint--bottom-left" data-hint="{{ "PLUGIN_BABEL.EXPORT_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.EXPORT"|tu }}
</span>
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -90,7 +116,7 @@

</tr>
{% endfor %}
</tbody>
</tbody>
</table>
{% endif %}
<div id="babels">
Expand All @@ -99,16 +125,27 @@
<table id='babels_table' class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>{{ "PLUGIN_BABEL.DEFINITION"|tu }}</th>
<th>{{ "PLUGIN_BABEL.TRANSLATION"|tu }}</th>
<th>{{ "PLUGIN_BABEL.TRANSLATIONS"|tu }}</th>
<th>
<span class="hint--bottom" data-hint="{{ "PLUGIN_BABEL.DEFINITION_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.DEFINITION"|tu }}
</span>
</th>
<th>
<span class="hint--bottom" data-hint="{{ "PLUGIN_BABEL.TRANSLATION_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.TRANSLATION"|tu }}
</span>
</th>
<th>
<span class="hint--bottom-left" data-hint="{{ "PLUGIN_BABEL.TRANSLATIONS_HINT"|t|e('html_attr') }}">
{{ "PLUGIN_BABEL.TRANSLATIONS"|tu }}
</th>
</tr>
</thead>
<tbody>

</tbody>
</table>

{% if domainfiles and domainfiles|length %}
<table id='babel_domain_packages' class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
Expand All @@ -125,8 +162,6 @@
{% endfor %}
</tbody>
</table>

<div

{% endif %}
</div>
{% endblock %}
15 changes: 15 additions & 0 deletions assets/admin/babel-quicktray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
((function($) {
$(document).ready(function() {
var Request, Toastr = null;
if (typeof Grav !== 'undefined' && Grav && Grav.default && Grav.default.Utils) {
Request = Grav.default.Utils.request;
Toastr = Grav.default.Utils.toastr;
}
var babelAdmin = $('#admin-nav-quick-tray .babel-translator-admin');
if (!babelAdmin.length) { return; }

babelAdmin.on('click', function(e) {
document.location = GravAdmin.config.base_url_relative + '/babel';
});
});
})(jQuery));
55 changes: 55 additions & 0 deletions assets/admin/babel.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
display: inline-block;
text-align: center;
font-size:larger;
margin-right: 10px;
}

#admin-main .admin-block .babel_save i {
Expand All @@ -52,3 +53,57 @@
display: none;
}

div.dataTables_wrapper div.dataTables_paginate {
margin: 0;
white-space: nowrap;
text-align: right;
}

.admin-block .pagination {
display: inline-block;
padding-left: 0;
margin: 20px 0;
border-radius: 4px;
}

.admin-block .pagination > li {
display: inline;
}

.admin-block .pagination > .active > a, .pagination > .active > span, .pagination > .active > a:hover, .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus {
z-index: 3;
color: #fff;
cursor: default;
background-color: #337ab7;
border-color: #337ab7;
}

.admin-block .pagination > li > a, .pagination > li > span {
position: relative;
float: left;
padding: 6px 12px;
margin-left: -1px;
line-height: 1.42857143;
color: rgba(255,255,255,0.85);
text-decoration: none;
background: #0090D9;
border: 1px solid #ddd;
border-radius: 4px;
border-top-color: rgb(221, 221, 221);
border-right-color: rgb(221, 221, 221);
border-bottom-color: rgb(221, 221, 221);
border-left-color: rgb(221, 221, 221);
white-space: nowrap;
}

#admin-main .admin-block .pagination a,
#admin-main .admin-block .pagination a:hover,
#admin-main .admin-block .pagination a:visited
{
color: rgba(255,255,255,0.85);
}


#admin-main .admin-block .input-sm {
min-width: 50%;
}
6 changes: 3 additions & 3 deletions assets/admin/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
});

$(document).on('click', '.admin-block .babel_copy', function() {
var $translation = $(this).closest('tr').find('.babel-translation').html();
var $translation = $(this).closest('.babel_translation').find('.babel-translation').html();
var $targetval = $(this).closest('tr').find('.babel_translated').val();
if ($targetval === '') {
$(this).closest('tr').find('.babel_translated').val($translation);
Expand Down Expand Up @@ -176,7 +176,7 @@
{ data: null, render: function ( data, type, row ) {
var $col = '<div class="babel_definition"><div class="babel_save' + (data.babelized == '1' ? ' button' : '') + '"><i class="fa fa-save"></i></div><input class="babel_doc_id" type="hidden" value="' + data.doc_id + '" />' +
data.language +
'<dl><dt>' + data.domain + '</dt><dd>' + data.doc_id.replace(data.language + '.' + data.domain + '.', '') + '</dd></dl></div>';
'<div>' + data.domain + '</div><div><strong>' + data.doc_id.replace(data.language + '.' + data.domain + '.', '') + '</strong></div>';
return $col;
} },
{ data: null, render: function ( data, type, row ) {
Expand All @@ -192,7 +192,7 @@
var $translations = JSON.parse(data.translations);
var $babel_translations = '<div class="babel_translations">';
$.each($translations, function(key, value) {
$babel_translations += '<button class="babel_copy"><strong>' + key + '</strong>:</button> <translation class="babel-translation" lang="' + key + '" dir="' + value[1] + '">' + value[0] + '</translation><br />';
$babel_translations += '<div class="babel_translation"><button class="babel_copy"><strong>' + key + '</strong>:</button> <translation class="babel-translation" lang="' + key + '" dir="' + value[1] + '">' + value[0] + '</translation></div>';
});
return $babel_translations + '</div>'
}
Expand Down
32 changes: 23 additions & 9 deletions babel.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public function onPluginsInitialized()
*/
public function onAdminTwigSiteVariables()
{

$this->grav['assets']->addJs('plugin://babel/assets/admin/babel-quicktray.js');
// Avoid unncessary processing...
$uri = $this->grav['uri'];
if (strpos($uri->path(), $this->config->get('plugins.admin.route') . '/' . $this->route) === false) {
return;
}

$twig = $this->grav['twig'];
list($status, $msg) = $this->getIndexCount();

Expand All @@ -96,13 +104,8 @@ public function onAdminTwigSiteVariables()
//$this->grav['babel']->createIndex();
} else {
$twig->twig_vars['babel_index_status'] = ['status' => $status, 'msg' => $msg];
// Avoid unncessary processing...
$uri = $this->grav['uri'];
if (strpos($uri->path(), $this->config->get('plugins.admin.route') . '/' . $this->route) === false) {
return;
}

$this->grav['assets']->addCss('plugin://babel/bower_components/bootstrap/dist/css/bootstrap.css');
//$this->grav['assets']->addCss('plugin://babel/bower_components/bootstrap/dist/css/bootstrap.css');
$this->grav['assets']->addCss('plugin://babel/assets/admin/babel.css');
$this->grav['assets']->addCss('plugin://babel/bower_components/datatables.net-bs/css/dataTables.bootstrap.css');
$this->grav['assets']->addCss('plugin://babel/bower_components/datatables.net-responsive-bs/css/responsive.bootstrap.css');
Expand Down Expand Up @@ -149,10 +152,21 @@ protected function getIndexCount()
*/
public function onAdminMenu()
{
$this->grav['twig']->plugins_hooked_nav['PLUGIN_BABEL.BABEL'] = [
'route' => $this->route,
'icon' => 'fa-language'
/** no need for full menu item, implement as optional according to recommendation by olevik **/
if (Grav::instance()['config']->get('plugins.babel.adminmenu', false)) {
$this->grav['twig']->plugins_hooked_nav['PLUGIN_BABEL.BABEL'] = [
'route' => $this->route,
'icon' => 'fa-language'
];
}
$options = [
'authorize' => '',
'hint' => 'Babel translator',
'class' => 'babel-translator-admin',
'icon' => 'fa-language'
];
$this->grav['twig']->plugins_quick_tray['Babel Translator'] = $options;

}

/**
Expand Down
Loading

0 comments on commit 8f518eb

Please sign in to comment.