@@ -296,3 +296,74 @@ describe('get-data on corrupt translations', () => {
296296 }
297297 } )
298298} )
299+
300+ describe ( 'get-data applies corrections to translated variables' , ( ) => {
301+ let dd : DataDirectory
302+ const enDirBefore = languages . en . dir
303+ languages . ja = Object . assign ( { } , languages . en , { } )
304+
305+ beforeAll ( ( ) => {
306+ dd = new DataDirectory ( {
307+ data : {
308+ variables : {
309+ myproduct : {
310+ name : 'GitHub' ,
311+ } ,
312+ phases : {
313+ preview : '{% ifversion ghes < 3.16 %}beta{% else %}public preview{% endif %}' ,
314+ } ,
315+ } ,
316+ } ,
317+ } )
318+ languages . en . dir = dd . root
319+
320+ const jaTranslationsRoot = path . join ( dd . root , 'translations' , 'ja-JP' )
321+ fs . mkdirSync ( jaTranslationsRoot , { recursive : true } )
322+ languages . ja . dir = jaTranslationsRoot
323+ new DataDirectory (
324+ {
325+ data : {
326+ variables : {
327+ myproduct : {
328+ // Corrupted: `data` translated to Japanese `γγΌγΏ`
329+ name : '{% γγΌγΏ variables.myproduct.name %}' ,
330+ } ,
331+ phases : {
332+ // Not corrupted β should pass through unchanged
333+ preview : '{% ifversion ghes < 3.16 %}γγΌγΏ{% else %}γγγͺγγ―γγ¬γγ₯γΌ{% endif %}' ,
334+ } ,
335+ } ,
336+ } ,
337+ } ,
338+ jaTranslationsRoot ,
339+ )
340+ } )
341+
342+ afterAll ( ( ) => {
343+ dd . destroy ( )
344+ languages . en . dir = enDirBefore
345+ } )
346+
347+ test ( 'corrects corrupted Liquid keywords in translated variables' , ( ) => {
348+ // English variable is returned as-is
349+ {
350+ const result = getDataByLanguage ( 'variables.myproduct.name' , 'en' )
351+ expect ( result ) . toBe ( 'GitHub' )
352+ }
353+ // Japanese translation with corrupted `γγΌγΏ` β `data` gets corrected
354+ {
355+ const result = getDataByLanguage ( 'variables.myproduct.name' , 'ja' )
356+ expect ( result ) . toBe ( '{% data variables.myproduct.name %}' )
357+ }
358+ } )
359+
360+ test ( 'leaves valid translated variables unchanged' , ( ) => {
361+ // Valid ifversion in translated variable should pass through
362+ {
363+ const result = getDataByLanguage ( 'variables.phases.preview' , 'ja' )
364+ expect ( result ) . toBe (
365+ '{% ifversion ghes < 3.16 %}γγΌγΏ{% else %}γγγͺγγ―γγ¬γγ₯γΌ{% endif %}' ,
366+ )
367+ }
368+ } )
369+ } )
0 commit comments