forked from wikimedia/wikipedia-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTWNStringsTests.m
433 lines (377 loc) · 23.8 KB
/
TWNStringsTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#import <XCTest/XCTest.h>
#import "WMFTestConstants.h"
@import WMF;
@interface TWNStringsTests : XCTestCase
@property (class, strong, nonatomic, readonly) NSArray *bundledLprojFiles;
@property (class, strong, nonatomic, readonly) NSArray *iOSLprojFiles;
@property (class, strong, nonatomic, readonly) NSArray *twnLprojFiles;
@property (class, strong, nonatomic, readonly) NSString *bundleRoot;
@property (class, strong, nonatomic, readonly) NSArray *twnInfoPlistFilePaths;
@property (class, strong, nonatomic, readonly) NSArray *iOSInfoPlistFilePaths;
@property (class, strong, nonatomic, readonly) NSString *twnLocalizationsDirectory;
@property (class, strong, nonatomic, readonly) NSString *iOSLocalizationsDirectory;
@end
@implementation TWNStringsTests
- (void)setUp {
[super setUp];
}
+ (NSString *)iOSLocalizationsDirectory {
NSString *sourceRootPath = [[NSBundle bundleForClass:[self class]] objectForInfoDictionaryKey:WMFSourceRootDirKey];
return [sourceRootPath stringByAppendingPathComponent:@"Wikipedia/iOS Native Localizations"];
}
+ (NSString *)twnLocalizationsDirectory {
NSString *sourceRootPath = [[NSBundle bundleForClass:[self class]] objectForInfoDictionaryKey:WMFSourceRootDirKey];
return [sourceRootPath stringByAppendingPathComponent:@"Wikipedia/Localizations"];
}
+ (NSString *)bundleRoot {
return [[NSBundle wmf_localizationBundle] bundlePath];
}
+ (NSString *)appBundleRoot {
return [[NSBundle mainBundle] bundlePath];
}
+ (NSArray *)bundledLprojFiles {
static dispatch_once_t onceToken;
static NSArray *bundledLprojFiles;
dispatch_once(&onceToken, ^{
bundledLprojFiles = [[[[NSFileManager defaultManager] contentsOfDirectoryAtPath:TWNStringsTests.bundleRoot error:nil] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension='lproj'"]] valueForKey:@"lowercaseString"];
});
return bundledLprojFiles;
}
+ (NSArray *)twnInfoPlistFilePaths {
static dispatch_once_t onceToken;
static NSArray *twnInfoPlistFilePaths;
dispatch_once(&onceToken, ^{
twnInfoPlistFilePaths = [self.twnLprojFiles wmf_map:^NSString *(NSString *lprojFileName) {
return [[self.twnLocalizationsDirectory stringByAppendingPathComponent:lprojFileName] stringByAppendingPathComponent:@"InfoPlist.strings"];
}];
});
return twnInfoPlistFilePaths;
}
+ (NSArray *)iOSInfoPlistFilePaths {
static dispatch_once_t onceToken;
static NSArray *infoPlistFilePaths;
dispatch_once(&onceToken, ^{
infoPlistFilePaths = [self.iOSLprojFiles wmf_map:^NSString *(NSString *lprojFileName) {
return [[self.iOSLocalizationsDirectory stringByAppendingPathComponent:lprojFileName] stringByAppendingPathComponent:@"InfoPlist.strings"];
}];
});
return infoPlistFilePaths;
}
+ (NSArray *)twnLprojFiles {
static dispatch_once_t onceToken;
static NSArray *twnLprojFiles;
dispatch_once(&onceToken, ^{
twnLprojFiles = [[[[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.twnLocalizationsDirectory error:nil] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension='lproj'"]] valueForKey:@"lowercaseString"];
});
return twnLprojFiles;
}
+ (NSArray *)iOSLprojFiles {
static dispatch_once_t onceToken;
static NSArray *iOSLprojFiles;
dispatch_once(&onceToken, ^{
iOSLprojFiles = [[[[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.iOSLocalizationsDirectory error:nil] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension='lproj'"]] valueForKey:@"lowercaseString"];
});
return iOSLprojFiles;
}
- (NSDictionary *)getPluralizableStringsDictFromLprogAtPath:(NSString *)lprojPath {
NSString *stringsFilePath = [lprojPath stringByAppendingPathComponent:@"Localizable.stringsdict"];
return [self getDictFromPListAtPath:stringsFilePath];
}
- (NSDictionary *)getTranslationStringsDictFromLprogAtPath:(NSString *)lprojPath {
NSString *stringsFilePath = [lprojPath stringByAppendingPathComponent:@"Localizable.strings"];
return [self getDictFromPListAtPath:stringsFilePath];
}
- (NSDictionary *)getDictFromPListAtPath:(NSString *)path {
BOOL isDirectory = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) {
return [NSDictionary dictionaryWithContentsOfFile:path];
}
return nil;
}
- (void)testLprojCount {
XCTAssert(TWNStringsTests.iOSLprojFiles.count > 0);
XCTAssert(TWNStringsTests.twnLprojFiles.count > 0);
}
+ (NSRegularExpression *)reverseiOSTokenRegex {
static dispatch_once_t onceToken;
static NSRegularExpression *reverseiOSTokenRegex;
dispatch_once(&onceToken, ^{
reverseiOSTokenRegex = [NSRegularExpression regularExpressionWithPattern:@"(:?[^%%])(:?[0-9]+)(?:[$])(:?[^@dDuUxXoOfeEgGcCsSpaAF])" options:0 error:nil];
});
return reverseiOSTokenRegex;
}
+ (NSRegularExpression *)reverseTWNTokenRegex {
static dispatch_once_t onceToken;
static NSRegularExpression *reverseTWNTokenRegex;
dispatch_once(&onceToken, ^{
reverseTWNTokenRegex = [NSRegularExpression regularExpressionWithPattern:@"(:?[0-9])(?:[$])(:?[^0-9])" options:0 error:nil];
});
return reverseTWNTokenRegex;
}
+ (NSRegularExpression *)twnTokenRegex {
static dispatch_once_t onceToken;
static NSRegularExpression *twnTokenRegex;
dispatch_once(&onceToken, ^{
twnTokenRegex = [NSRegularExpression regularExpressionWithPattern:@"(?:[$])(:?[0-9]+)" options:0 error:nil];
});
return twnTokenRegex;
}
+ (NSRegularExpression *)percentNumberRegex {
static dispatch_once_t onceToken;
static NSRegularExpression *percentNumberRegex;
dispatch_once(&onceToken, ^{
percentNumberRegex = [NSRegularExpression regularExpressionWithPattern:@"(?<!%)(?:[%%])(:?[0-9s])" options:0 error:nil];
});
return percentNumberRegex;
}
+ (NSRegularExpression *)iOSTokenRegex {
static dispatch_once_t onceToken;
static NSRegularExpression *iOSTokenRegex;
dispatch_once(&onceToken, ^{
iOSTokenRegex = [NSRegularExpression regularExpressionWithPattern:@"%([0-9]*)\\$?([@dDuUxXoOfeEgGcCsSpaAF])" options:0 error:nil];
});
return iOSTokenRegex;
}
+ (NSRegularExpression *)singlePercentRegex {
static dispatch_once_t onceToken;
static NSRegularExpression *singlePercentRegex;
dispatch_once(&onceToken, ^{
singlePercentRegex = [NSRegularExpression regularExpressionWithPattern:@"(?<!%)%(?![%@d])" options:0 error:nil];
});
return singlePercentRegex;
}
- (void)assertLprojFiles:(NSArray *)lprojFiles withTranslationStringsInDirectory:(NSString *)directory haveNoMatchesWithRegex:(NSRegularExpression *)regex {
XCTAssertNotNil(regex);
for (NSString *lprojFileName in lprojFiles) {
if (![TWNStringsTests localeForLprojFilenameIsAvailableOniOS:lprojFileName]) {
continue;
}
NSDictionary *stringsDict = [self getTranslationStringsDictFromLprogAtPath:[directory stringByAppendingPathComponent:lprojFileName]];
for (NSString *key in stringsDict) {
NSString *localizedString = stringsDict[key];
NSTextCheckingResult *result = [regex firstMatchInString:localizedString options:0 range:NSMakeRange(0, localizedString.length)];
XCTAssertNil(result, @"Invalid character in string: %@ for key: %@ in locale: %@", localizedString, key, lprojFileName);
}
}
}
- (void)assertLprojFiles:(NSArray *)lprojFiles withTranslationStringsInDirectory:(NSString *)directory doesNotContain:(NSString *)banned {
XCTAssertNotNil(banned);
NSString *bannedUpper = [banned uppercaseString];
for (NSString *lprojFileName in lprojFiles) {
if (![TWNStringsTests localeForLprojFilenameIsAvailableOniOS:lprojFileName]) {
continue;
}
NSDictionary *stringsDict = [self getTranslationStringsDictFromLprogAtPath:[directory stringByAppendingPathComponent:lprojFileName]];
for (NSString *key in stringsDict) {
NSString *localizedString = stringsDict[key];
BOOL doesContainBannedString = [[localizedString uppercaseString] containsString:bannedUpper];
XCTAssertFalse(doesContainBannedString, @"Invalid substring %@ found in: %@ for key: %@ in locale: %@", banned, localizedString, key, lprojFileName);
}
}
}
- (void)testiOSTranslationStringForTWNSubstitutionShortcuts {
[self assertLprojFiles:TWNStringsTests.iOSLprojFiles withTranslationStringsInDirectory:TWNStringsTests.bundleRoot haveNoMatchesWithRegex:TWNStringsTests.twnTokenRegex];
}
- (void)testIncomingTranslationStringForReversedSubstitutionShortcuts {
[self assertLprojFiles:TWNStringsTests.twnLprojFiles withTranslationStringsInDirectory:TWNStringsTests.twnLocalizationsDirectory haveNoMatchesWithRegex:TWNStringsTests.reverseTWNTokenRegex];
}
- (void)testiOSTranslationStringForReversedSubstitutionShortcuts {
[self assertLprojFiles:TWNStringsTests.iOSLprojFiles withTranslationStringsInDirectory:TWNStringsTests.bundleRoot haveNoMatchesWithRegex:TWNStringsTests.reverseiOSTokenRegex];
}
- (void)testIncomingTranslationStringForPercentTokens {
[self assertLprojFiles:TWNStringsTests.twnLprojFiles withTranslationStringsInDirectory:TWNStringsTests.twnLocalizationsDirectory haveNoMatchesWithRegex:TWNStringsTests.percentNumberRegex];
}
// Note: This test should fail for any incoming strings that have a single percent sign, but only if it is NOT followed by @ or d.
// Examples:
// "100% of my donation" should fail (string needs to be "100%% of my donation" to avoid crash)
// "Wszystkie karty %@ są ukryte" should pass
// "Zaviedli sme limit %d článkov na zoznam na prečítanie" should also pass
- (void)testIncomingTranslationStringForSinglePercentSigns {
[self assertLprojFiles:TWNStringsTests.twnLprojFiles withTranslationStringsInDirectory:TWNStringsTests.twnLocalizationsDirectory haveNoMatchesWithRegex:TWNStringsTests.singlePercentRegex];
}
+ (NSRegularExpression *)htmlTagRegex {
static NSRegularExpression *htmlTagRegex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
htmlTagRegex = [NSRegularExpression regularExpressionWithPattern:@"(<[^>]*>)([^<]*)" options:NSRegularExpressionCaseInsensitive error:nil];
});
return htmlTagRegex;
}
- (void)testIncomingTranslationStringForHTML {
[self assertLprojFiles:TWNStringsTests.twnLprojFiles withTranslationStringsInDirectory:TWNStringsTests.bundleRoot haveNoMatchesWithRegex:TWNStringsTests.htmlTagRegex];
}
- (void)testIncomingTranslationStringForNBSP {
[self assertLprojFiles:TWNStringsTests.twnLprojFiles withTranslationStringsInDirectory:TWNStringsTests.bundleRoot doesNotContain:@" "];
}
- (void)testIncomingTranslationStringForBracketSubstitutions {
for (NSString *lprojFileName in TWNStringsTests.twnLprojFiles) {
if (![lprojFileName isEqualToString:@"qqq.lproj"]) {
NSDictionary *stringsDict = [self getTranslationStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:lprojFileName]];
NSDictionary *pluralizableStringsDict = [self getPluralizableStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:lprojFileName]];
for (NSString *key in stringsDict) {
NSString *localizedString = stringsDict[key];
if ([localizedString containsString:@"{{"]) {
NSString *lowercaseString = localizedString.lowercaseString;
if ([lowercaseString containsString:@"{{plural:"]) {
XCTAssertNotNil([pluralizableStringsDict objectForKey:key], @"Localizable string %@ in %@ with PLURAL: needs an entry in the corresponding stringsdict file. This likely means that this language's Localizable.stringsdict hasn't been added to the project yet.", key, lprojFileName);
} else if (![lowercaseString containsString:@"{{formatnum:$"]) {
XCTAssertTrue(false, @"%@ in %@ has unsupported {{ }} in localization.", key, lprojFileName);
}
}
}
}
}
}
- (void)testiOSTranslationStringForBracketSubstitutionsAndMismatchedTokens {
NSDictionary *enStrings = [self getTranslationStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:@"en.lproj"]];
NSMutableDictionary *enTokensByKey = [NSMutableDictionary dictionaryWithCapacity:enStrings.count];
for (NSString *lprojFileName in TWNStringsTests.iOSLprojFiles) {
if (![lprojFileName isEqualToString:@"qqq.lproj"]) {
NSDictionary *stringsDict = [self getTranslationStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:lprojFileName]];
NSDictionary *pluralizableStringsDict = [self getPluralizableStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:lprojFileName]];
for (NSString *key in stringsDict) {
NSString *localizedString = stringsDict[key];
if ([localizedString containsString:@"{{"]) {
NSString *lowercaseString = localizedString.lowercaseString;
if ([lowercaseString containsString:@"{{plural:%"]) {
XCTAssertNotNil([pluralizableStringsDict objectForKey:key], @"Localizable string %@ in %@ with PLURAL: needs an entry in the corresponding stringsdict file. This likely means that this language's Localizable.stringsdict hasn't been added to the project yet.", key, lprojFileName);
} else {
XCTAssertTrue(false, @"Unsupported {{ }} in localization");
}
}
NSMutableDictionary *localizedTokens = [NSMutableDictionary new];
NSRegularExpression *tokenRegex = [TWNStringsTests iOSTokenRegex];
[tokenRegex enumerateMatchesInString:localizedString
options:0
range:NSMakeRange(0, localizedString.length)
usingBlock:^(NSTextCheckingResult *_Nullable result, NSMatchingFlags flags, BOOL *_Nonnull stop) {
NSString *tokenKey = [tokenRegex replacementStringForResult:result inString:localizedString offset:0 template:@"$1"];
if ([tokenKey isEqualToString:@""]) {
tokenKey = @"1";
XCTAssertNil(localizedTokens[tokenKey], @"There can only be one unordered token in a localization string. Switch to ordered tokens:\n%@\n%@", key, localizedString);
}
NSString *value = [tokenRegex replacementStringForResult:result inString:localizedString offset:0 template:@"$2"];
localizedTokens[tokenKey] = value;
}];
NSString *enString = enStrings[key];
NSMutableDictionary *enTokens = enTokensByKey[key];
if (enString) {
if (!enTokens) {
enTokens = [NSMutableDictionary new];
[tokenRegex enumerateMatchesInString:enString
options:0
range:NSMakeRange(0, enString.length)
usingBlock:^(NSTextCheckingResult *_Nullable result, NSMatchingFlags flags, BOOL *_Nonnull stop) {
NSString *tokenKey = [tokenRegex replacementStringForResult:result inString:enString offset:0 template:@"$1"];
if ([tokenKey isEqualToString:@""]) {
tokenKey = @"1";
XCTAssertNil(enTokens[tokenKey], @"There can only be one unordered token in a localization string. Switch to ordered tokens:\n%@\n%@", key, enString);
}
NSString *value = [tokenRegex replacementStringForResult:result inString:enString offset:0 template:@"$2"];
enTokens[tokenKey] = value;
}];
enTokensByKey[key] = enTokens;
}
XCTAssertEqualObjects(localizedTokens, enTokens, @"%@ translation for %@ has incorrect tokens:\n%@\n%@", lprojFileName, key, enString, localizedString);
}
}
}
}
}
- (NSArray *)unbundledLprojFiles {
NSMutableArray *files = [TWNStringsTests.twnLprojFiles mutableCopy];
[files removeObjectsInArray:TWNStringsTests.bundledLprojFiles];
return files;
}
- (NSArray *)unbundledLprojFilesWithTranslations {
// unbundled lProj's containing "Localizable.strings"
return
[self.unbundledLprojFiles wmf_select:^BOOL(NSString *lprojFileName) {
BOOL isDirectory = NO;
NSString *localizableStringsFilePath =
[[TWNStringsTests.twnLocalizationsDirectory stringByAppendingPathComponent:lprojFileName] stringByAppendingPathComponent:@"Localizable.strings"];
return [[NSFileManager defaultManager] fileExistsAtPath:localizableStringsFilePath isDirectory:&isDirectory];
}];
}
+ (NSSet<NSString *> *)supportedLocales {
static dispatch_once_t onceToken;
static NSSet<NSString *> *supportedLocales;
dispatch_once(&onceToken, ^{
NSArray *lowercaseAvailableLocales = [[NSLocale availableLocaleIdentifiers] wmf_map:^id(NSString *locale) {
return [locale lowercaseString];
}];
supportedLocales = [NSSet setWithArray:lowercaseAvailableLocales];
});
return supportedLocales;
}
+ (BOOL)localeForLprojFilenameIsAvailableOniOS:(NSString *)lprojFileName {
NSString *localeIdentifier = [[lprojFileName substringToIndex:lprojFileName.length - 6] lowercaseString]; // remove .lproj suffix
return [[TWNStringsTests supportedLocales] containsObject:localeIdentifier];
}
- (void)testAllSupportedTranslatedLanguagesWereAddedToProjectLocalizations {
// Fails if any supported languages have TWN translations (in "Wikipedia/Localizations/Localizable.strings") but are
// not yet bundled in the project.
// So, if this test fails, the languages listed will need to be added these to the project's localizations.
// To do this:
// 1. Go to the project editor, select the project name under Project, and click Info. Under Localizations, click the Add button (+), then choose a language combination from the pop-up menu.
// 2. Then in the project navigator, click the "Localizable" file in the "Localizations" group, and add a checkmark to your language in the file inspector.
// If you get warnings about existing localizations in previous two steps, choose option to use existing files.
NSArray *files = [self.unbundledLprojFilesWithTranslations mutableCopy];
for (NSString *file in files) {
XCTAssert(![TWNStringsTests localeForLprojFilenameIsAvailableOniOS:file], @"Missing supported translation for %@", file);
}
}
- (void)testKeysForUnderscores {
for (NSString *lprojFileName in TWNStringsTests.twnLprojFiles) {
NSDictionary *stringsDict = [self getTranslationStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:lprojFileName]];
for (NSString *key in stringsDict) {
// Keys use dash "-" separators.
XCTAssertFalse([key containsString:@"_"]);
}
}
}
// Translators need context for all substitutions. If a string has any substitutions, such as "$1" or "$2" etc, the string's comment needs to explain what will be substituted in place of "$1", "$2" etc.
- (void)testiOSTranslationCommentsForMentionOfEachSubstitution {
NSDictionary *enStrings = [self getDictFromPListAtPath:[[TWNStringsTests.twnLocalizationsDirectory stringByAppendingPathComponent:@"en.lproj"] stringByAppendingPathComponent:@"Localizable.strings"]];
NSDictionary *qqqStrings = [self getDictFromPListAtPath:[[TWNStringsTests.twnLocalizationsDirectory stringByAppendingPathComponent:@"qqq.lproj"] stringByAppendingPathComponent:@"Localizable.strings"]];
for (NSString *enKey in enStrings) {
// This test assumes each EN key is also present in QQQ.
XCTAssertTrue([qqqStrings valueForKey:enKey], @"Expected en key in qqq");
NSString *enString = enStrings[enKey];
NSString *qqqString = qqqStrings[enKey];
NSArray<NSTextCheckingResult *> *enSubstitutionMatches = [TWNStringsTests.twnTokenRegex matchesInString:enString options:0 range:NSMakeRange(0, enString.length)];
NSArray<NSTextCheckingResult *> *qqqSubstitutionMatches = [TWNStringsTests.twnTokenRegex matchesInString:qqqString options:0 range:NSMakeRange(0, qqqString.length)];
for (NSTextCheckingResult *enMatch in enSubstitutionMatches) {
NSString *enMatchString = [enString substringWithRange:enMatch.range];
BOOL didFindEnMatchStringAtLeastOnceInQQQMatchString = NO;
for (NSTextCheckingResult *qqqMatch in qqqSubstitutionMatches) {
NSString *qqqMatchString = [qqqString substringWithRange:qqqMatch.range];
if ([qqqMatchString isEqualToString:enMatchString]) {
didFindEnMatchStringAtLeastOnceInQQQMatchString = YES;
break;
}
}
XCTAssertTrue(didFindEnMatchStringAtLeastOnceInQQQMatchString, @"\n\tExpected each substitution (i.e. \"$1\") in string is mentioned at least once in its comment.\n\t\tString: \"%@\"\n\t\tComment: \"%@\"\n\t\tKey: \"%@\"\n\n", [enString stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"], [qqqString stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"], enKey);
if (!didFindEnMatchStringAtLeastOnceInQQQMatchString) {
// No need keep testing if a string already failed our assertion once.
break;
}
}
}
}
// Translators have been know to add "{{plural..." syntax to strings which don't yet have "{{plural..." in EN, which means the string won't be correctly resolved.
- (void)testIncomingTranslationStringForBracketSubstitutionsNotPresentInEN {
NSDictionary *enPluralizableStringsDict = [self getPluralizableStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:@"en.lproj"]];
for (NSString *lprojFileName in TWNStringsTests.twnLprojFiles) {
if (![lprojFileName isEqualToString:@"qqq.lproj"] && ![lprojFileName isEqualToString:@"en.lproj"]) {
NSDictionary *translationPluralizableStringsDict = [self getPluralizableStringsDictFromLprogAtPath:[TWNStringsTests.bundleRoot stringByAppendingPathComponent:lprojFileName]];
for (NSString *key in translationPluralizableStringsDict) {
XCTAssertNotNil([enPluralizableStringsDict objectForKey:key], @"\n\n\"%@\" translation containing plurals syntax received for \"%@\" string. The original EN string...\n\thttps://translatewiki.net/w/i.php?title=Wikimedia:Wikipedia-ios-%@/en&action=edit\n...doesn't have (or possibly need) plural syntax - either plural syntax will need to be added to the EN string or the translation...\n\thttps://translatewiki.net/w/i.php?title=Wikimedia:Wikipedia-ios-%@/%@&action=edit\n...will need to be updated to remove plural syntax.\n(Note: after loading the link above you can tap the \"Ask question\" button to pre-fill a Phabricator ticket for asking `i18n` folks for assistance for this string)\n\n", lprojFileName, key, key, key, [lprojFileName stringByReplacingOccurrencesOfString:@".lproj" withString:@""]);
}
}
}
}
- (void)tearDown {
[super tearDown];
}
@end