File tree Expand file tree Collapse file tree 3 files changed +81
-2
lines changed Expand file tree Collapse file tree 3 files changed +81
-2
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,69 @@ describe('PushWorker', () => {
157157 expect ( PushUtils . bodiesPerLocales ( { where : { } } ) ) . toEqual ( { default : { where : { } } } ) ;
158158 expect ( PushUtils . groupByLocaleIdentifier ( [ ] ) ) . toEqual ( { default : [ ] } ) ;
159159 } ) ;
160+
161+ it ( 'should propely apply translations strings' , ( ) => {
162+ const bodies = PushUtils . bodiesPerLocales ( {
163+ data : {
164+ alert : 'Yo!' ,
165+ } ,
166+ translation : {
167+ 'fr' : 'frenchy!' ,
168+ 'en' : 'english' ,
169+ }
170+ } , [ 'fr' , 'en' ] ) ;
171+ expect ( bodies ) . toEqual ( {
172+ fr : {
173+ data : {
174+ alert : 'frenchy!' ,
175+ }
176+ } ,
177+ en : {
178+ data : {
179+ alert : 'english' ,
180+ }
181+ } ,
182+ default : {
183+ data : {
184+ alert : 'Yo!'
185+ }
186+ }
187+ } ) ;
188+ } ) ;
189+
190+ it ( 'should propely apply translations objects' , ( ) => {
191+ const bodies = PushUtils . bodiesPerLocales ( {
192+ data : {
193+ alert : 'Yo!' ,
194+ badge : 'Increment' ,
195+ } ,
196+ translation : {
197+ 'fr' : { alert : 'frenchy!' , title : 'yolo' } ,
198+ 'en' : { alert : 'english' , badge : 2 , other : 'value' } ,
199+ }
200+ } , [ 'fr' , 'en' ] ) ;
201+ expect ( bodies ) . toEqual ( {
202+ fr : {
203+ data : {
204+ alert : 'frenchy!' ,
205+ title : 'yolo' ,
206+ }
207+ } ,
208+ en : {
209+ data : {
210+ alert : 'english' ,
211+ badge : 2 ,
212+ other : 'value'
213+ }
214+ } ,
215+ default : {
216+ data : {
217+ alert : 'Yo!' ,
218+ badge : 'Increment' ,
219+ }
220+ }
221+ } ) ;
222+ } ) ;
160223 } ) ;
161224
162225 describe ( 'pushStatus' , ( ) => {
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ export class PushQueue {
6565 pushStatus : { objectId : pushStatus . objectId } ,
6666 applicationId : config . applicationId
6767 } ;
68+ console . log ( body ) // eslint-disable-line
6869 this . parsePublisher . publish ( this . channel , JSON . stringify ( pushWorkItem ) ) ;
6970 } ) ;
7071 } ) . then ( ( ) => {
Original file line number Diff line number Diff line change @@ -52,14 +52,29 @@ export function stripLocalesFromBody(body) {
5252 return body ;
5353}
5454
55+ export function translateBody ( body , locale ) {
56+ body = deepcopy ( body ) ;
57+ if ( body . translation && body . translation [ locale ] && locale ) {
58+ const translation = body . translation [ locale ] ;
59+ if ( typeof translation === 'string' ) { // use translation
60+ body . data = body . data || { } ;
61+ body . data . alert = translation ;
62+ } else if ( typeof translation === 'object' ) { // override tranlsation
63+ body . data = translation ;
64+ }
65+ }
66+ delete body . translation ;
67+ return body ;
68+ }
69+
5570export function bodiesPerLocales ( body , locales = [ ] ) {
5671 // Get all tranformed bodies for each locale
5772 const result = locales . reduce ( ( memo , locale ) => {
58- memo [ locale ] = transformPushBodyForLocale ( body , locale ) ;
73+ memo [ locale ] = translateBody ( transformPushBodyForLocale ( body , locale ) , locale ) ;
5974 return memo ;
6075 } , { } ) ;
6176 // Set the default locale, with the stripped body
62- result . default = stripLocalesFromBody ( body ) ;
77+ result . default = translateBody ( stripLocalesFromBody ( body ) ) ;
6378 return result ;
6479}
6580
You can’t perform that action at this time.
0 commit comments