Improve MKV LanguageBCP47 conversion
This commit is contained in:
3 files changed
+14
-3
No files matched your search
@@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (NSString *)localizedLangForExtendedTag:(NSString *)tag;
|
||||
|
||||
- (BOOL)validateExtendedTag:(NSString *)tag;
|
||||
- (nullable NSString *)normalizedExtendedTag:(NSString *)tag;
|
||||
|
||||
/**
|
||||
Returns the complete ISO-639-1 language code list
|
||||
|
||||
+12
-2
@@ -817,8 +817,18 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
#pragma mark - Validation
|
||||
|
||||
- (BOOL)validateExtendedTag:(NSString *)tag {
|
||||
NSString *fixedCode = [tag stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
|
||||
return [NSLocale.availableLocaleIdentifiers containsObject:fixedCode];
|
||||
NSString *fixedTag = [tag stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
|
||||
return [NSLocale.availableLocaleIdentifiers containsObject:fixedTag];
|
||||
}
|
||||
|
||||
- (nullable NSString *)normalizedExtendedTag:(NSString *)tag {
|
||||
NSString *fixedTag = [tag stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
|
||||
for (NSString *identifier in NSLocale.availableLocaleIdentifiers) {
|
||||
if ([identifier caseInsensitiveCompare:fixedTag] == NSOrderedSame) {
|
||||
return [identifier stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
newTrack.name = trackName;
|
||||
}
|
||||
if (mkvTrack->LanguageBCP47) {
|
||||
newTrack.language = @(mkvTrack->LanguageBCP47);
|
||||
newTrack.language = [MP42Languages.defaultManager normalizedExtendedTag:@(mkvTrack->LanguageBCP47)];
|
||||
} else {
|
||||
newTrack.language = [MP42Languages.defaultManager extendedTagForISO_639_2b:@(mkvTrack->Language)];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user