Brion VIBBER has uploaded a new change for review.

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

Change subject: Work in progress: fallback-friendly MWLocalizedString to 
replcae NSLocalizedString
......................................................................

Work in progress: fallback-friendly MWLocalizedString to replcae 
NSLocalizedString

Not using everywhere just yet because it'll involve a lot of search-and-replace
and will play hell with the next merge, so will do after. :D

Change-Id: I465d76b3c48e36c14b91c9582d30229f5b0d541c
---
M Wikipedia-iOS/View Controllers/MainMenu/MainMenuViewController.m
M Wikipedia-iOS/mw-utils/WikipediaAppUtils.h
M Wikipedia-iOS/mw-utils/WikipediaAppUtils.m
3 files changed, 27 insertions(+), 1 deletion(-)


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

diff --git a/Wikipedia-iOS/View Controllers/MainMenu/MainMenuViewController.m 
b/Wikipedia-iOS/View Controllers/MainMenu/MainMenuViewController.m
index 810bfc4..757f999 100644
--- a/Wikipedia-iOS/View Controllers/MainMenu/MainMenuViewController.m
+++ b/Wikipedia-iOS/View Controllers/MainMenu/MainMenuViewController.m
@@ -192,7 +192,7 @@
     NSString *currentArticleTitle = [SessionSingleton 
sharedInstance].currentArticleTitle;
     
     NSAttributedString *searchWikiTitle =
-    [NSLocalizedString(@"main-menu-language-title", nil) 
attributedStringWithAttributes: nil
+    [MWLocalizedString(@"main-menu-language-title", nil) 
attributedStringWithAttributes: nil
                                                                     
substitutionStrings: @[[SessionSingleton sharedInstance].domainName]
                                                                  
substitutionAttributes: @[self.self.highlightedTextAttributes]
      ];
diff --git a/Wikipedia-iOS/mw-utils/WikipediaAppUtils.h 
b/Wikipedia-iOS/mw-utils/WikipediaAppUtils.h
index 0555bd7..f921bb6 100644
--- a/Wikipedia-iOS/mw-utils/WikipediaAppUtils.h
+++ b/Wikipedia-iOS/mw-utils/WikipediaAppUtils.h
@@ -2,8 +2,11 @@
 
 #import <Foundation/Foundation.h>
 
+#define MWLocalizedString(key, throwaway) [WikipediaAppUtils 
localizedStringForKey:key]
+
 @interface WikipediaAppUtils : NSObject
 
 +(NSString*) appVersion;
++(NSString*) localizedStringForKey:(NSString *)key;
 
 @end
diff --git a/Wikipedia-iOS/mw-utils/WikipediaAppUtils.m 
b/Wikipedia-iOS/mw-utils/WikipediaAppUtils.m
index 55b1eaf..b37b8f5 100644
--- a/Wikipedia-iOS/mw-utils/WikipediaAppUtils.m
+++ b/Wikipedia-iOS/mw-utils/WikipediaAppUtils.m
@@ -14,4 +14,27 @@
             ];
 }
 
++(NSString*) localizedStringForKey:(NSString *)key
+{
+    // Based on handy sample from 
http://stackoverflow.com/questions/3263859/localizing-strings-in-ios-default-fallback-language/8784451#8784451
+    //
+    // NSLocalizedString doesn't fall back on languages on a string-by-string
+    // basis, so missing keys in a localization file give us the key name
+    // instead of the English version we expected.
+    //
+    // If we get the key back, go load up the English bundle and fetch
+    // the string from there instead.
+    NSString *outStr = NSLocalizedString(key, nil);
+    if ([outStr isEqualToString:key]) {
+        // If we got the message key back, we have failed. :P
+        // Note this isn't very efficient probably, but should
+        // only be used in rare fallback cases anyway.
+        NSString *path = [[NSBundle mainBundle] pathForResource:@"en" 
ofType:@"lproj"];
+        NSBundle *languageBundle = [NSBundle bundleWithPath:path];
+        return [languageBundle localizedStringForKey:key value:@"" table:nil];
+    } else {
+        return outStr;
+    }
+}
+
 @end

-- 
To view, visit https://gerrit.wikimedia.org/r/125326
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I465d76b3c48e36c14b91c9582d30229f5b0d541c
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER <br...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to