iOS character localization 1. Localization Repository 1.1. Create a new bundle as a localized repository
1.2. Change the localization repository to the following
1.3. Configure local character (localizable.strings) resources for each language
English
"Group" = "group";
"Name" = "Name";
Chinese Simplified
"Group" = "group";
"Name" = "First-line Day";
Chinese Traditional
"Group" = "group";
"Name" = "one line day";
2. Processing local conversion Extensions 2.1. New bundle Extension Class
2.2. Implementing the NSBundle extension method
//
Nsbundle+localizationstring.h
Localizationstringtest
//
Created by Vie on 2017/1/20.
Copyright? 2017 Vie. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSBundle (localizationstring)
/**
Returning localized characters based on system language
@param key Character Key
@return Localized characters
*/
+ (NSString *) Localizationstringforkey: (NSString *) key;
@end
//
Nsbundle+localizationstring.m
Localizationstringtest
//
Created by Vie on 2017/1/20.
Copyright? 2017 Vie. All rights reserved.
//
#import "Nsbundle+localizationstring.h"
@implementation NSBundle (localizationstring)
/**
Returning localized characters based on system language
@param key Character Key
@return Localized characters
*/
+ (NSString *) Localizationstringforkey: (NSString *) key{
static NSBundle const *bundle=nil;
if (Bundle==nil) {
(The language strings acquired by iOS are not stable) The current framework handles only three cases of EN, Zh-hans, zh-hant, and others are handled by default
NSString *language = [Nslocale preferredlanguages].firstobject;
if ([Language hasprefix:@ "en"]) {
Language = @ "en";
} else if ([Language hasprefix:@ "zh"]) {
if ([Language rangeofstring:@ "Hans"].location! = Nsnotfound) {
Language = @ "Zh-hans"; Chinese Simplified
} else {//ZH-HANT\ZH-HK\ZH-TW
Language = @ "Zh-hant"; Traditional Chinese
}
} else {
Language = @ "Zh-hans";
}
Initializing resources
Bundle=[nsbundle bundlewithpath:[[nsbundle bundlewithpath:[[nsbundle Mainbundle] pathForResource:@ " Localizationstring "oftype:@" bundle "] pathforresource:language oftype:@" Lproj "];
}
return [bundle Localizedstringforkey:key Value:nil Table:nil];
}
@end
3. Localized character key3.1. Localized character key implementation
//
LocalizationKey.h
Localizationstringtest
Local Session character Key list
Created by Vie on 2017/1/20.
Copyright? 2017 Vie. All rights reserved.
//
#define GROUP @ "group"
#define NAME @ "Name"
4. Use
#import "Nsbundle+localizationstring.h"
#import "LocalizationKey.h"
NSLog (@ "%@|%@", [NSBundle localizationstringforkey:group],[nsbundle localizationstringforkey:name]);
IOS, localized characters