@ -237,43 +237,41 @@ enum ScriptAction: String {
}
break
case . updatePermissionStrings :
print ( " ------------ Updating permission strings ------------ " )
var strings : JSON = projectState . infoPlistLocalizationFile . strings
var updatedInfoPlistJSON : JSON = projectState . infoPlistLocalizationFile . json
ProjectState . permissionStrings . forEach { key in
guard let nsKey : String = ProjectState . permissionStringsMap [ key ] else { return }
var updatedStrings : JSON = projectState . localizationFile . strings [ key ] as ! JSON
if let localizations : JSON = updatedStrings [ " localizations " ] as ? JSON {
var updatedLocalizations : JSON = localizations
localizations . forEach { locale , stringUint in
var updatedStringUnit : JSON = stringUint as ! JSON
if let translation : JSON = updatedStringUnit [ " stringUnit " ] as ? JSON ,
let value : String = translation [ " value " ] as ? String
{
var updatedTranslation : JSON = translation
let updatedValue : String = value . replacingOccurrences ( of : " {app_name} " , with : " Session " )
updatedTranslation [ " value " ] = updatedValue
updatedStringUnit [ " stringUnit " ] = updatedTranslation
updatedLocalizations [ locale ] = updatedStringUnit
}
}
updatedStrings [ " localizations " ] = updatedLocalizations
}
strings [ nsKey ] = updatedStrings
}
updatedInfoPlistJSON [ " strings " ] = strings
if let data : Data = try ? JSONSerialization . data ( withJSONObject : updatedInfoPlistJSON , options : [ . fragmentsAllowed ] ) {
do {
try data . write ( to : URL ( fileURLWithPath : projectState . infoPlistLocalizationFile . path ) , options : [ . atomic ] )
} catch {
fatalError ( " Could not write to InfoPlist.xcstrings, error: \( error ) " )
}
}
break
// p r i n t ( " - - - - - - - - - - - - U p d a t i n g p e r m i s s i o n s t r i n g s - - - - - - - - - - - - " )
// v a r u p d a t e d I n f o P l i s t J S O N : J S O N = p r o j e c t S t a t e . i n f o P l i s t L o c a l i z a t i o n F i l e . j s o n
// v a r s t r i n g s : J S O N = u p d a t e d I n f o P l i s t J S O N [ " s t r i n g s " ] a s ! J S O N
// p r o j e c t S t a t e . l o c a l i z a t i o n F i l e s . f o r E a c h { f i l e i n
// P r o j e c t S t a t e . p e r m i s s i o n S t r i n g s . f o r E a c h { k e y i n
// g u a r d l e t n s K e y : S t r i n g = P r o j e c t S t a t e . p e r m i s s i o n S t r i n g s M a p [ k e y ] e l s e { r e t u r n }
// v a r k e y P h r a s e s : J S O N = s t r i n g s [ n s K e y ] a s ! J S O N
// v a r l o c a l i z a t i o n s : J S O N = k e y P h r a s e s [ " l o c a l i z a t i o n s " ] a s ! J S O N
// i f l e t p h r a s e : S t r i n g = f i l e . k e y P h r a s e [ k e y ] ? . v a l u e {
// i f l e t t r a n s l a t i o n s : J S O N = l o c a l i z a t i o n s [ f i l e . n a m e ] a s ? J S O N {
// v a r s t r i n g U n i t : J S O N = t r a n s l a t i o n s [ " s t r i n g U n i t " ] a s ! J S O N
// i f ( s t r i n g U n i t [ " v a l u e " ] a s ! S t r i n g ) ! = p h r a s e {
// s t r i n g U n i t [ " s t a t e " ] = " t r a n s l a t e d "
// s t r i n g U n i t [ " v a l u e " ] = p h r a s e
// }
// } e l s e {
// l e t s t r i n g U n i t : J S O N = [
// " s t a t e " : " t r a n s l a t e d " ,
// " v a l u e " : p h r a s e . r e p l a c i n g O c c u r r e n c e s ( o f : " \ " " , w i t h : " " )
// ]
// l o c a l i z a t i o n s [ f i l e . n a m e ] = [ " s t r i n g U n i t " : s t r i n g U n i t ]
// }
// }
// k e y P h r a s e s [ " l o c a l i z a t i o n s " ] = l o c a l i z a t i o n s
// s t r i n g s [ n s K e y ] = k e y P h r a s e s
// }
// }
// u p d a t e d I n f o P l i s t J S O N [ " s t r i n g s " ] = s t r i n g s
//
// i f l e t d a t a : D a t a = t r y ? J S O N S e r i a l i z a t i o n . d a t a ( w i t h J S O N O b j e c t : u p d a t e d I n f o P l i s t J S O N , o p t i o n s : [ . f r a g m e n t s A l l o w e d ] ) {
// d o {
// t r y d a t a . w r i t e ( t o : U R L ( f i l e U R L W i t h P a t h : p r o j e c t S t a t e . i n f o P l i s t L o c a l i z a t i o n F i l e . p a t h ) , o p t i o n s : [ . a t o m i c ] )
// } c a t c h {
// f a t a l E r r o r ( " C o u l d n o t w r i t e t o I n f o P l i s t . x c s t r i n g s , e r r o r : \ ( e r r o r ) " )
// }
// }
}
print ( " ------------ Complete ------------ " )
@ -402,6 +400,7 @@ extension ProjectState {
struct XCStringsFile : Locatable {
let name : String
let path : String
var json : JSON
var strings : JSON
var locales : Set < String > = Set ( )
@ -413,7 +412,8 @@ extension ProjectState {
. components ( separatedBy : " / " )
. last ? ? " Unknown " )
self . path = path
self . strings = XCStringsFile . parse ( path ) [ " strings " ] as ! JSON
self . json = XCStringsFile . parse ( path )
self . strings = self . json [ " strings " ] as ! JSON
self . strings . values . forEach { value in
if let localizations : JSON = ( value as ? JSON ) ? [ " localizations " ] as ? JSON {
self . locales . formUnion ( localizations . map { $0 . key } )