@@ -181,49 +181,50 @@ Template.mfTrans.helpers({
181
181
}
182
182
} ) ;
183
183
184
+ Template . registerHelper ( 'strings' , function ( ) {
185
+ var orig = mfPkg . native ;
186
+ var lang = RouterLayer . getParam ( 'lang' ) ;
187
+
188
+ // summarise matching keys (orig + trans) to a single record
189
+ var out = { } , strings = mfPkg . mfStrings . find ( {
190
+ $and : [ { $or : [ { lang : orig } , { lang : lang } ] } ,
191
+ { removed : undefined } ]
192
+ } ) . fetch ( ) ;
193
+
194
+ _ . each ( strings , function ( str ) {
195
+ if ( ! out [ str . key ] )
196
+ out [ str . key ] = { key : str . key } ;
197
+ if ( str . lang == orig )
198
+ out [ str . key ] . orig = str . text ;
199
+ else
200
+ out [ str . key ] . trans = str . text ;
201
+ if ( str . fuzzy )
202
+ out [ str . key ] . fuzzy = true ;
203
+ } ) ;
204
+
205
+ strings = _ . values ( out ) ;
206
+ strings . sort ( function ( a , b ) {
207
+ if ( ! a . trans && b . trans )
208
+ return - 1 ;
209
+ else if ( a . trans && ! b . trans )
210
+ return 1 ;
211
+
212
+ if ( ! a . fuzzy && b . fuzzy )
213
+ return - 1 ;
214
+ else if ( b . fuzzy && ! a . fuzzy )
215
+ return 1 ;
216
+
217
+ return a . text - b . text ;
218
+ } ) ;
219
+
220
+ return strings ;
221
+ } ) ;
222
+
184
223
Template . mfTransLang . helpers ( {
185
224
origLang : mfPkg . native ,
186
225
destLang : function ( ) { return RouterLayer . getParam ( 'lang' ) ; } ,
187
226
allowed : function ( ) {
188
227
return ! mfPkg . webUI . allowed . call ( this ) || mfPkg . webUI . denied . call ( this ) ;
189
- } ,
190
- strings : function ( ) {
191
- var orig = mfPkg . native ;
192
- var lang = RouterLayer . getParam ( 'lang' ) ;
193
-
194
- // summarise matching keys (orig + trans) to a single record
195
- var out = { } , strings = mfPkg . mfStrings . find ( {
196
- $and : [ { $or : [ { lang : orig } , { lang : lang } ] } ,
197
- { removed : undefined } ]
198
- } ) . fetch ( ) ;
199
-
200
- _ . each ( strings , function ( str ) {
201
- if ( ! out [ str . key ] )
202
- out [ str . key ] = { key : str . key } ;
203
- if ( str . lang == orig )
204
- out [ str . key ] . orig = str . text ;
205
- else
206
- out [ str . key ] . trans = str . text ;
207
- if ( str . fuzzy )
208
- out [ str . key ] . fuzzy = true ;
209
- } ) ;
210
-
211
- strings = _ . values ( out ) ;
212
- strings . sort ( function ( a , b ) {
213
- if ( ! a . trans && b . trans )
214
- return - 1 ;
215
- else if ( a . trans && ! b . trans )
216
- return 1 ;
217
-
218
- if ( ! a . fuzzy && b . fuzzy )
219
- return - 1 ;
220
- else if ( b . fuzzy && ! a . fuzzy )
221
- return 1 ;
222
-
223
- return a . text - b . text ;
224
- } ) ;
225
-
226
- return strings ;
227
228
}
228
229
} ) ;
229
230
@@ -261,11 +262,14 @@ Template.mfTransLang.events({
261
262
262
263
Template . mfTransLang . helpers ( {
263
264
sortedStrings : function ( ) {
265
+ var strings = Blaze . _globalHelpers [ 'strings' ] ;
266
+ if ( ! strings ) return ;
267
+
264
268
var sortField = Session . get ( 'translationSortField' ) ;
265
269
if ( ! sortField ) {
266
270
Session . set ( 'translationSortField' , 'orig' ) ;
267
271
}
268
- return this . strings . sort ( function ( a , b ) {
272
+ return strings ( ) . sort ( function ( a , b ) {
269
273
return a [ sortField ] > b [ sortField ] ? 1 : ( a [ sortField ] < b [ sortField ] ? - 1 : 0 ) ;
270
274
} ) ;
271
275
} ,
0 commit comments