Bgerstle has submitted this change and it was merged. Change subject: Fix for article centric strings not using article lang localizations. ......................................................................
Fix for article centric strings not using article lang localizations. Native element localization is based on the device's lang. However, there are certain localization strings which appear in the context of an article. These should always use the article lang not the device lang. Among these strings: -"Contents" at the top of the table of contents. -"Page issues" and "Similar pages" buttons at top of articles. -"Quick facts" and "Other information" collapsed table headers. -"Close" collapsed table footer. -"Read more", "Edited by...", "Other langs..." and licence article footer text. -"Read more" results (were not being retrieved from current article's language wiki) This patch uses the current article's language when retrieving these localized strings and read more results. Bug reproduction steps: -from "Read in other languages" at the bottom of an enwiki article, pick Russian. -when it loads, you'll see the strings listed above all appear in English. Since all of these strings are within the context of the Russian article, they should be in Russian too. With this patch, they are. Note: some strings may still show in English if translations have not yet been received. (presently "Page issues" and "Similar pages" strings will still be English) T96809 Change-Id: I2e6c318dd9dc18a1e623c27279ebb4df9c987046 --- M Wikipedia/Categories/MWKSection+TOC.m M Wikipedia/Networking/Fetchers/SearchResultFetcher.h M Wikipedia/Networking/Fetchers/SearchResultFetcher.m M Wikipedia/Protocols/WMFLocalizationProtocol.m M Wikipedia/Session/SessionSingleton.h M Wikipedia/Session/SessionSingleton.m M Wikipedia/View Controllers/SearchResults/SearchResultsController.m M Wikipedia/View Controllers/TableOfContents/TOCViewController.m M Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.h M Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.m M Wikipedia/View Controllers/WebView/Footer/SubFooters/Options/WMFOptionsFooterViewController.m M Wikipedia/View Controllers/WebView/Footer/SubFooters/ReadMore/WMFReadMoreViewController.m M Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.h M Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.m M Wikipedia/View Controllers/WebView/WebViewController.m M Wikipedia/mw-utils/WikipediaAppUtils.h M Wikipedia/mw-utils/WikipediaAppUtils.m 17 files changed, 73 insertions(+), 13 deletions(-) Approvals: Bgerstle: Looks good to me, approved jenkins-bot: Verified diff --git a/Wikipedia/Categories/MWKSection+TOC.m b/Wikipedia/Categories/MWKSection+TOC.m index 8929328..01325f9 100644 --- a/Wikipedia/Categories/MWKSection+TOC.m +++ b/Wikipedia/Categories/MWKSection+TOC.m @@ -35,7 +35,7 @@ NSFontAttributeName: [UIFont fontWithName:@"Times New Roman" size:24.0 * MENUS_SCALE_MULTIPLIER] }; - NSString* heading = MWLocalizedString(@"table-of-contents-heading", nil); + NSString* heading = MWCurrentArticleLanguageLocalizedString(@"table-of-contents-heading", nil); if ([[SessionSingleton sharedInstance].currentArticleSite.language isEqualToString:@"en"]) { heading = [heading uppercaseString]; diff --git a/Wikipedia/Networking/Fetchers/SearchResultFetcher.h b/Wikipedia/Networking/Fetchers/SearchResultFetcher.h index 003cff4..161b981 100644 --- a/Wikipedia/Networking/Fetchers/SearchResultFetcher.h +++ b/Wikipedia/Networking/Fetchers/SearchResultFetcher.h @@ -40,6 +40,7 @@ - (instancetype)initAndSearchForTerm:(NSString*)searchTerm searchType:(SearchType)searchType searchReason:(SearchReason)searchReason + language:(NSString *)language maxResults:(NSUInteger)maxResults withManager:(AFHTTPRequestOperationManager*)manager thenNotifyDelegate:(id <FetchFinishedDelegate>)delegate; diff --git a/Wikipedia/Networking/Fetchers/SearchResultFetcher.m b/Wikipedia/Networking/Fetchers/SearchResultFetcher.m index 0434995..7990b7a 100644 --- a/Wikipedia/Networking/Fetchers/SearchResultFetcher.m +++ b/Wikipedia/Networking/Fetchers/SearchResultFetcher.m @@ -22,6 +22,7 @@ @property (nonatomic, strong) NSString* searchSuggestion; @property (nonatomic, strong) NSRegularExpression* spaceCollapsingRegex; +@property (nonatomic, strong) NSString* language; @end @@ -30,6 +31,7 @@ - (instancetype)initAndSearchForTerm:(NSString*)searchTerm searchType:(SearchType)searchType searchReason:(SearchReason)searchReason + language:(NSString *)language maxResults:(NSUInteger)maxResults withManager:(AFHTTPRequestOperationManager*)manager thenNotifyDelegate:(id <FetchFinishedDelegate>)delegate { @@ -40,6 +42,7 @@ self.searchTerm = searchTerm ? searchTerm : @""; self.searchType = searchType; self.searchReason = searchReason; + self.language = language; self.fetchFinishedDelegate = delegate; self.maxSearchResults = maxResults ? maxResults : SEARCH_MAX_RESULTS; self.spaceCollapsingRegex = @@ -50,7 +53,7 @@ } - (void)searchWithManager:(AFHTTPRequestOperationManager*)manager { - NSString* url = [SessionSingleton sharedInstance].searchApiUrl; + NSString* url = [[SessionSingleton sharedInstance] searchApiUrlForLanguage:self.language]; NSDictionary* params = [self getParams]; diff --git a/Wikipedia/Protocols/WMFLocalizationProtocol.m b/Wikipedia/Protocols/WMFLocalizationProtocol.m index a99e9a2..fcb2a8c 100644 --- a/Wikipedia/Protocols/WMFLocalizationProtocol.m +++ b/Wikipedia/Protocols/WMFLocalizationProtocol.m @@ -46,7 +46,7 @@ } -(NSString *)getTranslationForKey:(NSString *)key { - return MWLocalizedString(key, nil); + return MWCurrentArticleLanguageLocalizedString(key, nil); } - (void)sendResponseWithData:(NSData*)data{ diff --git a/Wikipedia/Session/SessionSingleton.h b/Wikipedia/Session/SessionSingleton.h index 84c7af0..deb29f9 100644 --- a/Wikipedia/Session/SessionSingleton.h +++ b/Wikipedia/Session/SessionSingleton.h @@ -91,6 +91,9 @@ @property (strong, nonatomic, readonly) NSString* searchApiUrl; +- (NSString*)searchApiUrlForLanguage:(NSString *)language; +- (NSString*)searchLanguage; + @property (nonatomic) BOOL fallback; - (NSURL*)urlForLanguage:(NSString*)language; diff --git a/Wikipedia/Session/SessionSingleton.m b/Wikipedia/Session/SessionSingleton.m index ed0d4eb..b7f7869 100644 --- a/Wikipedia/Session/SessionSingleton.m +++ b/Wikipedia/Session/SessionSingleton.m @@ -193,8 +193,12 @@ #pragma mark - Search - (NSString*)searchApiUrl { + return [self searchApiUrlForLanguage:self.searchLanguage]; +} + +- (NSString*)searchApiUrlForLanguage:(NSString *)language { NSString* endpoint = self.fallback ? @"" : @".m"; - return [NSString stringWithFormat:@"https://%@%@.%@/w/api.php", self.searchLanguage, endpoint, self.currentArticleSite.domain]; + return [NSString stringWithFormat:@"https://%@%@.%@/w/api.php", language, endpoint, self.currentArticleSite.domain]; } - (void)setSearchLanguage:(NSString*)searchLanguage { diff --git a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m index e899708..bceda63 100644 --- a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m +++ b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m @@ -231,7 +231,7 @@ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - if (self.type == WMFSearchResultsControllerTypeReadMore) { + if ([self isReadMore]) { self.searchResultsTable.scrollEnabled = NO; [self.searchResultsTable wmf_shouldScrollToTopOnStatusBarTap:NO]; } else { @@ -516,7 +516,7 @@ self.searchSuggestion = [searchResultFetcher.searchSuggestion copy]; } if (self.searchSuggestion) { - [self.didYouMeanButton showWithText:MWLocalizedString(@"search-did-you-mean", nil) + [self.didYouMeanButton showWithText:([self isReadMore]) ? MWCurrentArticleLanguageLocalizedString(@"search-did-you-mean", nil) : MWLocalizedString(@"search-did-you-mean", nil) term:self.searchSuggestion]; } } else if ([sender isKindOfClass:[ThumbnailFetcher class]]) { @@ -569,10 +569,23 @@ } } +-(BOOL)isReadMore { + return (self.type == WMFSearchResultsControllerTypeReadMore); +} + +-(NSString *)getSearchLanguage { + if ([self isReadMore]) { + return [SessionSingleton sharedInstance].currentArticleSite.language; + }else{ + return [SessionSingleton sharedInstance].searchLanguage; + } +} + - (void)performSupplementalFullTextSearchForTerm:(NSString*)searchTerm { (void)[[SearchResultFetcher alloc] initAndSearchForTerm:searchTerm searchType:SEARCH_TYPE_IN_ARTICLES searchReason:SEARCH_REASON_SUPPLEMENT_PREFIX_WITH_FULL_TEXT + language:[self getSearchLanguage] maxResults:[self maxResultsAdjustedForExcludedArticles] withManager:[QueuesSingleton sharedInstance].searchResultsFetchManager thenNotifyDelegate:self]; @@ -589,6 +602,7 @@ (void)[[SearchResultFetcher alloc] initAndSearchForTerm:searchTerm searchType:SEARCH_TYPE_TITLES searchReason:reason + language:[self getSearchLanguage] maxResults:[self maxResultsAdjustedForExcludedArticles] withManager:[QueuesSingleton sharedInstance].searchResultsFetchManager thenNotifyDelegate:self]; diff --git a/Wikipedia/View Controllers/TableOfContents/TOCViewController.m b/Wikipedia/View Controllers/TableOfContents/TOCViewController.m index 2c3275a..78db6b7 100644 --- a/Wikipedia/View Controllers/TableOfContents/TOCViewController.m +++ b/Wikipedia/View Controllers/TableOfContents/TOCViewController.m @@ -598,7 +598,7 @@ @"id": @(100000), @"isLead": @(NO), @"level": @0, - @"title": MWLocalizedString(@"article-read-more-title", @"Read more") + @"title": MWCurrentArticleLanguageLocalizedString(@"article-read-more-title", @"Read more") }]; self.tocSectionData = allSectionData; diff --git a/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.h b/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.h index 38fca72..35f5651 100644 --- a/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.h +++ b/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.h @@ -5,4 +5,6 @@ @interface WMFLegalFooterViewController : UIViewController +-(void)updateLocalizedText; + @end diff --git a/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.m b/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.m index 7a8bf70..e1bccc1 100644 --- a/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.m +++ b/Wikipedia/View Controllers/WebView/Footer/SubFooters/Legal/WMFLegalFooterViewController.m @@ -38,7 +38,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - self.licenseLabel.attributedText = [self getAttributedStringForLicense]; + [self updateLocalizedText]; [self adjustConstraintsScaleForViews:@[self.licenseLabel, self.wordmarkImageView]]; } @@ -57,14 +57,18 @@ NSFontAttributeName: [UIFont systemFontOfSize:kLicenseFontSize * MENUS_SCALE_MULTIPLIER] }; - NSString* footerText = MWLocalizedString(@"license-footer-text", nil); + NSString* footerText = MWCurrentArticleLanguageLocalizedString(@"license-footer-text", nil); return [footerText attributedStringWithAttributes:baseStyle - substitutionStrings:@[MWLocalizedString(@"license-footer-name", nil)] + substitutionStrings:@[MWCurrentArticleLanguageLocalizedString(@"license-footer-name", nil)] substitutionAttributes:@[substitutionStyle]]; } +-(void)updateLocalizedText { + self.licenseLabel.attributedText = [self getAttributedStringForLicense]; +} + #pragma mark Tap gesture handling - (IBAction)licenseTapped:(id)sender { diff --git a/Wikipedia/View Controllers/WebView/Footer/SubFooters/Options/WMFOptionsFooterViewController.m b/Wikipedia/View Controllers/WebView/Footer/SubFooters/Options/WMFOptionsFooterViewController.m index 2a453f3..b1e1e9f 100644 --- a/Wikipedia/View Controllers/WebView/Footer/SubFooters/Options/WMFOptionsFooterViewController.m +++ b/Wikipedia/View Controllers/WebView/Footer/SubFooters/Options/WMFOptionsFooterViewController.m @@ -109,7 +109,7 @@ } - (NSAttributedString*)getAttributedStringForOptionLanguagesWithCount:(NSInteger)count { - NSString* langButtonString = [MWLocalizedString(@"language-button-text", nil) stringByReplacingOccurrencesOfString:@"%d" withString:@"$1"]; + NSString* langButtonString = [MWCurrentArticleLanguageLocalizedString(@"language-button-text", nil) stringByReplacingOccurrencesOfString:@"%d" withString:@"$1"]; return [langButtonString attributedStringWithAttributes:[self getOptionTextBaseAttributes] @@ -131,7 +131,7 @@ - (NSAttributedString*)getAttributedStringForOptionLastModifiedByUserName:(NSString*)userName date:(NSDate*)date { NSString* relativeTimeStamp = [WikipediaAppUtils relativeTimestamp:date]; - NSString* lastModString = userName ? MWLocalizedString(@"lastmodified-by-user", nil) : MWLocalizedString(@"lastmodified-by-anon", nil); + NSString* lastModString = userName ? MWCurrentArticleLanguageLocalizedString(@"lastmodified-by-user", nil) : MWCurrentArticleLanguageLocalizedString(@"lastmodified-by-anon", nil); return [lastModString attributedStringWithAttributes:[self getOptionTextBaseAttributes] diff --git a/Wikipedia/View Controllers/WebView/Footer/SubFooters/ReadMore/WMFReadMoreViewController.m b/Wikipedia/View Controllers/WebView/Footer/SubFooters/ReadMore/WMFReadMoreViewController.m index 7359746..495c436 100644 --- a/Wikipedia/View Controllers/WebView/Footer/SubFooters/ReadMore/WMFReadMoreViewController.m +++ b/Wikipedia/View Controllers/WebView/Footer/SubFooters/ReadMore/WMFReadMoreViewController.m @@ -27,7 +27,7 @@ self.titleLabel.padding = UIEdgeInsetsMake(0, 0, 20, 10); self.titleLabel.font = [UIFont fontWithName:@"Times New Roman" size:26.0f * MENUS_SCALE_MULTIPLIER]; - self.titleLabel.text = MWLocalizedString(@"article-read-more-title", @"Read more"); + [self updateLocalizedText]; self.view.layer.cornerRadius = 2.0f * MENUS_SCALE_MULTIPLIER; self.view.clipsToBounds = YES; @@ -35,7 +35,12 @@ [self adjustConstraintsScaleForViews:@[self.titleLabel, self.optionsContainerView]]; } +-(void)updateLocalizedText{ + self.titleLabel.text = MWCurrentArticleLanguageLocalizedString(@"article-read-more-title", @"Read more"); +} + - (void)search { + [self updateLocalizedText]; self.searchSuggestionsController.searchString = self.searchString; self.searchSuggestionsController.articlesToExcludeFromResults = self.articlesToExcludeFromResults; [self.searchSuggestionsController search]; diff --git a/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.h b/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.h index 8bad2e1..76e9eb5 100644 --- a/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.h +++ b/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.h @@ -11,6 +11,7 @@ - (void)updateLanguageCount:(NSInteger)count; - (void)updateLastModifiedDate:(NSDate*)date userName:(NSString*)userName; +- (void)updateLegalFooterLocalizedText; @property (nonatomic, readonly) CGFloat footerHeight; diff --git a/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.m b/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.m index dc9aaaa..a4ec2ee 100644 --- a/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.m +++ b/Wikipedia/View Controllers/WebView/Footer/WMFWebViewFooterViewController.m @@ -66,6 +66,10 @@ [self.optionsController updateLastModifiedDate:date userName:userName]; } +- (void)updateLegalFooterLocalizedText { + [self.legalViewController updateLocalizedText]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } diff --git a/Wikipedia/View Controllers/WebView/WebViewController.m b/Wikipedia/View Controllers/WebView/WebViewController.m index bd9538e..7b866bd 100644 --- a/Wikipedia/View Controllers/WebView/WebViewController.m +++ b/Wikipedia/View Controllers/WebView/WebViewController.m @@ -1562,6 +1562,7 @@ [self.footerViewController updateLanguageCount:langCount]; [self.footerViewController updateLastModifiedDate:lastModified userName:lastModifiedByUserName]; [self.footerViewController updateReadMoreForArticle:article]; + [self.footerViewController updateLegalFooterLocalizedText]; // Add spacer above bottom native tracking component. [sectionTextArray addObject:@"<div style='background-color:transparent;height:40px;'></div>"]; diff --git a/Wikipedia/mw-utils/WikipediaAppUtils.h b/Wikipedia/mw-utils/WikipediaAppUtils.h index 6307d33..5d82f3b 100644 --- a/Wikipedia/mw-utils/WikipediaAppUtils.h +++ b/Wikipedia/mw-utils/WikipediaAppUtils.h @@ -16,6 +16,7 @@ // TODO: use stable channel constants #define MWLocalizedString(key, throwaway) [WikipediaAppUtils localizedStringForKey : key] +#define MWCurrentArticleLanguageLocalizedString(key, throwaway) [WikipediaAppUtils currentArticleLanguageLocalizedString : key] /** * Provides compile time checking for keypaths on a given object. @@ -62,6 +63,7 @@ + (NSString*)formFactor; + (NSString*)versionedUserAgent; + (NSString*)localizedStringForKey:(NSString*)key; ++ (NSString*)currentArticleLanguageLocalizedString:(NSString*)key; + (NSString*)relativeTimestamp:(NSDate*)date; + (NSString*)domainNameForCode:(NSString*)code; + (NSString*)wikiLangForSystemLang:(NSString*)code; diff --git a/Wikipedia/mw-utils/WikipediaAppUtils.m b/Wikipedia/mw-utils/WikipediaAppUtils.m index 6b7ad69..0fb76d5 100644 --- a/Wikipedia/mw-utils/WikipediaAppUtils.m +++ b/Wikipedia/mw-utils/WikipediaAppUtils.m @@ -3,6 +3,7 @@ #import "WikipediaAppUtils.h" #import "WMFAssetsFile.h" +#import "SessionSingleton.h" NSUInteger MegabytesToBytes(NSUInteger m){ static NSUInteger const MEGABYTE = 1 << 20; @@ -57,6 +58,21 @@ ]; } + ++ (NSString*)currentArticleLanguageLocalizedString:(NSString*)key { + MWKSite* site = [SessionSingleton sharedInstance].currentArticleSite; + NSString* path = [[NSBundle mainBundle] pathForResource:site.language ofType:@"lproj"]; + NSBundle* languageBundle = [NSBundle bundleWithPath:path]; + NSString *translation = nil; + if (languageBundle) { + translation = [languageBundle localizedStringForKey:key value:@"" table:nil]; + } + if (!translation || [translation isEqualToString:key] || (translation.length == 0)) { + return MWLocalizedString(key, nil); + } + return translation; +} + + (NSString*)localizedStringForKey:(NSString*)key { // Based on handy sample from http://stackoverflow.com/questions/3263859/localizing-strings-in-ios-default-fallback-language/8784451#8784451 // -- To view, visit https://gerrit.wikimedia.org/r/205918 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2e6c318dd9dc18a1e623c27279ebb4df9c987046 Gerrit-PatchSet: 6 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: Bgerstle <bgers...@wikimedia.org> Gerrit-Reviewer: Dr0ptp4kt <ab...@wikimedia.org> Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits