This commit is contained in:
giuseppenuc committed 2016-12-20 16:02:27 +01:00
1 parent 1bf4b9ef1d
commit 4e66c377fd
664 files changed
+14818 -10172

No files matched your search

@@ -10,7 +10,4 @@
@interface DJLocalizableString : NSString
- (NSUInteger)length;
- (unichar)characterAtIndex:(NSUInteger)index;
@end
@@ -11,13 +11,12 @@
@interface DJLocalizationSystem (Private)
/*!
* Special version that tries to load a storyboard string from all the tables
* except Localizable and InfoPlist. Defaults to comment if not found.
* Special version that tries to load a storyboard string from all the tables
* except Localizable and InfoPlist. Defaults to comment if not found.
*
* @param key The localization key
* @param comment The localization value
*
* @return The localized string
* @param key The localization key
* @param comment The localization value
* @return The localized string
*/
- (NSString *)localizedStoryboardStringForKey:(NSString *)key value:(NSString *)comment;
@@ -8,14 +8,19 @@
#import <Foundation/Foundation.h>
#define DJLocalizedString(key, comment) \
[DJLocalizationSystem.shared localizedStringForKey:(key) value: @"" table: nil]
#define DJLocalizedStringFromTable(key, tbl, comment) \
[DJLocalizationSystem.shared localizedStringForKey:(key) value: @"" table:(tbl)]
// replace Apple's macros with our own
#undef NSLocalizedString
#define NSLocalizedString(key, comment) \
[DJLocalizationSystem.shared localizedStringForKey:(key) value: @"" table: nil]
DJLocalizedString(key, comment)
#undef NSLocalizedStringFromTable
#define NSLocalizedStringFromTable(key, tbl, comment) \
[DJLocalizationSystem.shared localizedStringForKey:(key) value:@"" table:(tbl)]
DJLocalizedStringFromTable(key, tbl, comment)
@interface DJLocalizationSystem : NSObject
@@ -24,7 +29,7 @@
*
* @return A localization system instance
*/
+ (instancetype)shared;
@property (class, nonnull, readonly) DJLocalizationSystem *shared;
/*!
* Get the localized string for a given key/value
@@ -34,7 +39,7 @@
* @param tableName The localization table name
* @return The localized string
*/
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment table:(NSString *)tableName;
- (nonnull NSString *)localizedStringForKey:(nullable NSString *)key value:(nullable NSString *)comment table:(nullable NSString *)tableName;
/*!
* Get the localized string for a given key/value in the specified bundle
@@ -44,7 +49,7 @@
* @param bundle The bundle to search in
* @return The localized string
*/
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment table:(NSString *)tableName bundle:(NSBundle *)bundle;
- (nonnull NSString *)localizedStringForKey:(nullable NSString *)key value:(nullable NSString *)comment table:(nullable NSString *)tableName bundle:(nonnull NSBundle *)bundle;
/*!
* Reset the localization to the system's default language
@@ -54,11 +59,11 @@
/*!
* The bundle for the currently active language
*/
@property (nonatomic, readonly) NSBundle *bundle;
@property (nonatomic, readonly, nonnull) NSBundle *bundle;
/*!
* The currently active language
*/
@property (nonatomic, strong) NSString *language;
@property (nonatomic, strong, nonnull) NSString *language;
@end
@@ -16,6 +16,6 @@
* @param name The storyboard's name
* @return The desired storyboard
*/
+ (instancetype)dj_storyboardWithName:(NSString *)name;
+ (nonnull instancetype)dj_storyboardWithName:(nonnull NSString *)name;
@end
+12 -1
View File
@@ -25,6 +25,11 @@ it, simply add the following line to your Podfile:
pod "DJLocalization"
For Swift, use:
pod "DJLocalization/Swift"
### Manually
_**Important note if your project doesn't use ARC**: you must add the `-fobjc-arc` compiler flag to all 'DJLocalization' files in Target Settings > Build Phases > Compile Sources._
@@ -37,11 +42,17 @@ _**Important note if your project doesn't use ARC**: you must add the `-fobjc-ar
Then simply add the following import to your prefix header, or any file where you use the NSLocalizedString macro (or variants).
#import <DJLocalization/DJLocalization.h>
@import DJLocalization;
#####*Important:*
You must import the header wherever you use the NSLocalizedString macro, as this header replaces the default NSLocalizedString macro with a custom one. If you don't, runtime switching of languages won't work.
### Localization
Use your normal localization workflow and everything should work correctly. For code strings use `NSLocalizedString`, for storyboards use Base Internationalization.
As mentioned before, `NSLocalizedString` will only work correctly if you first include the correct headers. If you want a bit more safety, the library provides some extra macros `DJLocalizedString` that provide the same functionality as the overridden `NSLocalizedString` macros. This way you'll get a compilation error if you forget to include the headers.
### Switching languages
At runtime, you can switch the language at any time by setting the language property: