Skip to content

Commit f1c6471

Browse files
tomitrescakMartinFournier
authored andcommitted
Ability to show/hide the key and sort by the key
1 parent 32cd5b2 commit f1c6471

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

msgfmt:ui/lib/client.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,34 @@ Template.mfTrans.events({
244244
var unsavedDest;
245245
Template.mfTransLang.events({
246246
'click #mfTransLang tr': function(event) {
247-
changeKey(this.key);
247+
var tr = $(event.target).parents('tr');
248+
var key = tr.data('key');
249+
if (key) changeKey(key);
250+
},
251+
'click #translationShowKey': function(event) {
252+
Session.set('translationShowKey', event.currentTarget.checked);
253+
},
254+
'click .translationSort': function(event) {
255+
Session.set('translationSortField', event.currentTarget.attributes['data-sortField'].value);
248256
},
249257
'keyup #mfTransDest': function(event) {
250258
unsavedDest = event.target.value;
251259
}
252260
});
253261

254262
Template.mfTransLang.helpers({
263+
sortedStrings: function() {
264+
var sortField = Session.get('translationSortField');
265+
if (!sortField) {
266+
Session.set('translationSortField', 'orig');
267+
}
268+
return this.strings.sort(function(a, b) {
269+
return a[sortField] > b[sortField] ? 1 : (a[sortField] < b[sortField] ? -1 : 0);
270+
});
271+
},
272+
showKey: function() {
273+
return Session.get('translationShowKey');
274+
},
255275
stateClass: function() {
256276
if (this.fuzzy)
257277
return 'fuzzy';

msgfmt:ui/lib/ui.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ div.mfTransGraph.untrans { background: #800; border-right: 1px solid black; }
4949
#mfTransPreview table { width: 100%; table-layout:fixed; border-collapse:separate; background: white; }
5050
#mfTransPreview table thead tr { background: #ede9e3; }
5151
#mfTransPreview table thead th { width: 50%; padding: 4px 8px 4px 8px; }
52+
#mfTransPreview table thead th {
53+
border-left: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black;
54+
}
5255
#mfTransPreview table thead th:first-child {
5356
border-left: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black;
5457
border-top-left-radius: 5px;

msgfmt:ui/lib/ui.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,29 @@ <h2>{{mf 'mf_site_translations' 'Site Translations'}}</h2>
6666
</template>
6767

6868
<template name="mfTransLang">
69+
{{ debug }}
6970
<div class="container" id="mfTransLang">
7071

7172
<div id="mfTransPreview">
7273
<table>
7374
<thead>
7475
<tr>
75-
<th>Original String ({{origLang}})</th>
76-
<th>Translation ({{destLang}})</th>
76+
{{#if showKey}}
77+
<th><a href="#" class="translationSort" data-sortField="key">Key</a></th>
78+
{{/if}}
79+
<th><a href="#" class="translationSort" data-sortField="orig">Original String ({{orig}})</a></th>
80+
<th>Translation ({{trans}})</th>
7781
</tr>
7882
</thead>
7983
</table>
8084
<div class="tbodyScroll">
8185
<table>
8286
<tbody>
83-
{{#each strings}}
87+
{{#each sortedStrings}}
8488
<tr data-key="{{key}}" class="{{stateClass}} {{isCurrent}}">
89+
{{#if showKey}}
90+
<td>{{key}}</td>
91+
{{/if}}
8592
<td>{{orig}}</td>
8693
<td>{{trans}}</td>
8794
</tr>
@@ -90,7 +97,7 @@ <h2>{{mf 'mf_site_translations' 'Site Translations'}}</h2>
9097
</table>
9198
</div>
9299
</div>
93-
<p>Use ctrl-up and ctrl-down to quickly change keys</p>
100+
<p><input type="checkbox" id="translationShowKey">Show key, Use ctrl-up and ctrl-down to quickly change keys</p>
94101
<span><b>{{keyInfo.key}}</b> in {{keyInfo.file}}:{{keyInfo.line
95102
}}{{#if keyInfo.template}} (template
96103
{{#if keyInfo.routeUrl}}
@@ -117,4 +124,4 @@ <h2>{{mf 'mf_site_translations' 'Site Translations'}}</h2>
117124
<h1>{{mf 'access_denied' 'Access Denied'}}</h1>
118125
<p>{{mf 'login_and_access' 'Please ensure you are logged in and have the relevant access to add/edit translations.'}}</p>
119126
</div>
120-
</template>
127+
</template>

0 commit comments

Comments
 (0)