2018-11-18 20:31:22 +00:00
'use strict' ;
function convertToFake ( dict ) {
function convertValueToFakeLang ( str ) {
let from = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+\\|`~[{]};:'\",<.>/?" ;
let to = "ɐqɔpǝɟƃɥı ɾʞʅɯ uodbɹsʇnʌʍxʎz∀ԐↃᗡƎℲ⅁HIſ Ӽ⅂WNOԀÒᴚS⊥∩ɅM X⅄Z0123456789¡@#$%ᵥ⅋⁎()-_=+\\|,~[{]};:,„´<.>/¿" ;
return str . replace ( /(\{\{[^\}]+\}\}|%s)/g , '\x00\x04$1\x00' ) . split ( '\x00' ) . map ( c => {
if ( c . charAt ( 0 ) === '\x04' ) {
return c ;
}
let r = '' ;
for ( let i = 0 , len = c . length ; i < len ; i ++ ) {
let pos = from . indexOf ( c . charAt ( i ) ) ;
if ( pos < 0 ) {
r += c . charAt ( i ) ;
} else {
r += to . charAt ( pos ) ;
}
}
return r ;
} ) . join ( '\x00' ) . replace ( /[\x00\x04]/g , '' ) ;
}
function _convertToFake ( dict , fakeDict ) {
for ( const key in dict ) {
const val = dict [ key ] ;
if ( typeof val === 'string' ) {
fakeDict [ key ] = convertValueToFakeLang ( val ) ;
} else {
fakeDict [ key ] = _convertToFake ( val , { } ) ;
}
}
return fakeDict ;
}
return _convertToFake ( dict , { } ) ;
}
2018-11-20 22:41:10 +00:00
// The langugage labels below are intentionally not localized so that they are always native in the langugae of their speaker (regardless of the currently selected language)
2018-11-18 20:31:22 +00:00
const langCodes = {
en _US : {
2018-11-20 22:41:10 +00:00
getShortLabel : t => 'EN' ,
getLabel : t => 'English' ,
2018-11-18 20:31:22 +00:00
shortCode : 'en' ,
longCode : 'en_US'
} ,
es : {
2018-11-20 22:41:10 +00:00
getShortLabel : t => 'ES' ,
getLabel : t => 'Español' ,
2018-11-18 20:31:22 +00:00
shortCode : 'es' ,
longCode : 'es'
} ,
fake : {
2018-11-20 22:41:10 +00:00
getShortLabel : t => 'FAKE' ,
getLabel : t => 'Fake' ,
2018-11-18 20:31:22 +00:00
shortCode : 'fake' ,
longCode : 'fake'
}
}
2018-11-22 14:21:15 +00:00
langCodes . en = langCodes [ 'en-US' ] = langCodes . en _US ;
2018-11-18 20:31:22 +00:00
module . exports . convertToFake = convertToFake ;
module . exports . langCodes = langCodes ;