Mhurd has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/205809

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.

This patch uses the current article's language when retrieving
these localized strings.

Reproduction steps: from "Read in other languages" at the bottom
of an enwiki article, pick Chinese. 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 article, they
should all share the article language.

Change-Id: Ifdfdd6d0481ba18cf8a6658cb243939994b87577
---
M Wikipedia/Categories/MWKSection+TOC.m
M Wikipedia/Protocols/WMFLocalizationProtocol.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
13 files changed, 45 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia 
refs/changes/09/205809/1

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/Protocols/WMFLocalizationProtocol.m 
b/Wikipedia/Protocols/WMFLocalizationProtocol.m
index 6f70573..8b089c9 100644
--- a/Wikipedia/Protocols/WMFLocalizationProtocol.m
+++ b/Wikipedia/Protocols/WMFLocalizationProtocol.m
@@ -46,7 +46,7 @@
 
 -(NSString *)getTranslationForKey:(NSString *)key {
     if (key && (key.length > 0)) {
-        return MWLocalizedString(key, nil);
+        return MWCurrentArticleLanguageLocalizedString(key, nil);
     }else{
         return @"";
     }
diff --git a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m 
b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
index e899708..418f621 100644
--- a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
+++ b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
@@ -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.type == 
WMFSearchResultsControllerTypeReadMore) ? 
MWCurrentArticleLanguageLocalizedString(@"search-did-you-mean", nil) : 
MWLocalizedString(@"search-did-you-mean", nil)
                                            term:self.searchSuggestion];
         }
     } else if ([sender isKindOfClass:[ThumbnailFetcher class]]) {
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 0b8b049..65ceb9e 100644
--- a/Wikipedia/View Controllers/WebView/WebViewController.m
+++ b/Wikipedia/View Controllers/WebView/WebViewController.m
@@ -1569,6 +1569,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/205809
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifdfdd6d0481ba18cf8a6658cb243939994b87577
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mhurd <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to