@@ -1066,6 +1066,79 @@ user.password=Contraseña
10661066 expect ( spaceIdx ) . toBeLessThan ( stringKeys . indexOf ( "apple" ) ) ;
10671067 }
10681068 } ) ;
1069+
1070+ it ( "should respect shouldTranslate: false flag" , async ( ) => {
1071+ setupFileMocks ( ) ;
1072+
1073+ // Create input with a key that has shouldTranslate: false
1074+ const input = `{
1075+ "sourceLanguage": "en",
1076+ "strings": {
1077+ "do_not_translate": {
1078+ "shouldTranslate": false,
1079+ "localizations": {
1080+ "en": {
1081+ "stringUnit": {
1082+ "state": "translated",
1083+ "value": "This should not be translated"
1084+ }
1085+ }
1086+ }
1087+ },
1088+ "normal_key": {
1089+ "extractionState": "manual",
1090+ "localizations": {
1091+ "en": {
1092+ "stringUnit": {
1093+ "state": "translated",
1094+ "value": "This should be translated"
1095+ }
1096+ }
1097+ }
1098+ }
1099+ }
1100+ }` ;
1101+
1102+ mockFileOperations ( input ) ;
1103+
1104+ const xcodeXcstringsLoader = createBucketLoader ( "xcode-xcstrings" , "i18n/[locale].xcstrings" , { isCacheRestore : false , defaultLocale : "en" } ) ;
1105+ xcodeXcstringsLoader . setDefaultLocale ( "en" ) ;
1106+
1107+ // Pull data and verify that the shouldTranslate: false entry is skipped
1108+ const data = await xcodeXcstringsLoader . pull ( "en" ) ;
1109+
1110+ expect ( data ) . toHaveProperty ( "normal_key" , "This should be translated" ) ;
1111+ expect ( data ) . not . toHaveProperty ( "do_not_translate" ) ;
1112+
1113+ // Now push a translation for the normal key
1114+ const payload = {
1115+ "normal_key" : "Ceci devrait être traduit"
1116+ } ;
1117+
1118+ await xcodeXcstringsLoader . push ( "fr" , payload ) ;
1119+
1120+ expect ( fs . writeFile ) . toHaveBeenCalled ( ) ;
1121+ const writeFileCall = ( fs . writeFile as any ) . mock . calls [ 0 ] ;
1122+ const writtenContent = JSON . parse ( writeFileCall [ 1 ] ) ;
1123+
1124+ // Verify that the normal key was translated
1125+ expect ( writtenContent . strings . normal_key . localizations . fr . stringUnit . value ) . toBe ( "Ceci devrait être traduit" ) ;
1126+
1127+ // Verify that the do_not_translate key was preserved with its shouldTranslate: false flag
1128+ expect ( writtenContent . strings . do_not_translate ) . toHaveProperty ( "shouldTranslate" , false ) ;
1129+
1130+ // Check that the do_not_translate key has no localizations for the target language
1131+ expect ( writtenContent . strings . do_not_translate . localizations ) . not . toHaveProperty ( "fr" ) ;
1132+
1133+ // Now also test pushing with empty {} content to verify the flag is still preserved
1134+ await xcodeXcstringsLoader . push ( "fr" , { } ) ;
1135+
1136+ const secondWriteFileCall = ( fs . writeFile as any ) . mock . calls [ 1 ] ;
1137+ const secondWrittenContent = JSON . parse ( secondWriteFileCall [ 1 ] ) ;
1138+
1139+ // Verify the flag is still there
1140+ expect ( secondWrittenContent . strings . do_not_translate ) . toHaveProperty ( "shouldTranslate" , false ) ;
1141+ } ) ;
10691142 } ) ;
10701143
10711144 describe ( "yaml bucket loader" , ( ) => {
0 commit comments