Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS PHAssetCollection localizedTitle always returning english name

I'm using Apples Photos Framework to load PHAssetCollections into my app. I Always get the english name of the smart collections. For instance I get 'Favorites' instead of 'Favoriter' (Swedish). I thought the localizedTitle property would return the language the Simulator or the iPhone ran. (Running on a iPhone with Swedish language and region).

Has anyone else encountered this? Example code:

NSArray *collectionsFetchResults;
NSMutableArray *localizedTitles = [[NSMutableArray alloc] init];

PHFetchResult *smartAlbums = [PHAssetCollection       fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
                                                                            subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
PHFetchResult *syncedAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
                                                                       subtype:PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];
PHFetchResult *userCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];

// Add each PHFetchResult to the array
collectionsFetchResults = @[smartAlbums, userCollections, syncedAlbums];

for (int i = 0; i < collectionsFetchResults.count; i ++) {

    PHFetchResult *fetchResult = collectionsFetchResults[i];

    for (int x = 0; x < fetchResult.count; x ++) {

        PHCollection *collection = fetchResult[x];
        localizedTitles[x] = collection.localizedTitle;
        NSLog(@"%@", collection.localizedTitle); //<= Always prints english names
    }
}
like image 477
Objective Coder Avatar asked Mar 03 '17 12:03

Objective Coder


2 Answers

The reason for why collection.localizedTitle doesn't return any other language because your app has only one Localization that is English. This is definitely an Apple Bug, but here is a hack follow these steps.

  1. Create related folder sv.lproj apart from en.lproj folder that you already have.
  2. Add a blank text file in the folder, then add the file into your project.
  3. Performing step 2. you are adding Swedish Language support to your Project.
  4. Run your code, it should return Title in Swedish.

Update

If you want to add more languages easily after adding the blank text, you can add like showed in other answer by selecting Project, and in Localization section add language and choose blank file again, as we don't want to localize other files.

Hope it helps, if doubt ask here.

Cheers.

like image 184
iphonic Avatar answered Nov 09 '22 22:11

iphonic


I think you should just make sure you app support Swedish. Add the language you want to support Swedish for example add Swedish language

like image 27
陈星旺 Avatar answered Nov 09 '22 21:11

陈星旺