IOS PHAssetCollection localizedTitle always returns English name

I am using the Apples Photos Framework to upload PHAssetCollections to my application. I always get the English name for smart collections. For example, I get “Favorites” instead of “Favorite” (Swedish). I thought that the localizedTitle property would return the language in which the simulator or iPhone. (Work on iPhone with the Swedish language and region).

Has anyone else come across this? Code example:

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 } } 
+5
source share
4 answers

The reason collection.localizedTitle does not return any other language, because your application has only one localization of English . This is definitely an Apple Bug, but here's a hack to these steps.

  • Create the linked sv.lproj folder separately from the en.lproj folder that you already have.
  • Add an empty text file to the folder, and then add the file to your project.
  • In step 2., you add Swedish language support to your project.
  • Run your code, it should return Title in Swedish.

Update

If you want to add more languages ​​after adding blank text, you can add, as shown in another answer, selecting “Project”, and in the “Localization” section add the language and select the empty file again, since we do not want to localize other files.

Hope this helps if in doubt.

Greetings.

+4
source

I think you just need to make sure that you support the Swedish language. Add the language you want to support, for example, in Sweden add swedish language

+1
source

Your problem may be that none of your selections explicitly or implicitly return a built-in favorite smart album. (In addition, this would help with the diagnosis so that your code does not examine the results of only one sample, so you could figure out which one contains the non-localizing Favorites.)

If you explicitly want the Favorites collection, find it with a subtype of the PHAssetCollectionSubtypeSmartAlbumFavorites collection. (This should not happen as a result of searching for a regular album or a synchronized album, and I would be surprised to see it in top-level user collections, as this is documented to return only user-created collections.)

If a non-localizing version is returned in an explicit request for a selected smart album, or one of your other sets returns a selected smart album, and it does not localize, it is probably Apple's error - I would recommend letting them know .

0
source

ProJect → Localization → "+ Chinese (Simplified)" enter image description here

-1
source

Source: https://habr.com/ru/post/1264984/


All Articles