Using different languages ​​for system views than the current device language

In the application, I only want to support the German language. This is good with all texts that I define myself, but I cannot change the texts displayed by the views provided by the system, for example, the UISearchBar cancel button:

UISearchBar with English localization

If the device language is set to German, the cancel button displays “Abbreviated” correctly. However, if I set the device language to English (or any other language), the button shows “Cancel”, which is not true, since everything in the application is in German, so I want to have this button in German too. Can this be done? What am I doing wrong?

  • I only have the de.lproj folder, and I don't have the en.lproj folder. I have InfoPlist.strings and my main nib files inside the de.lproj folder.
  • The alias for representing the contents of the UIViewController , whose searchDisplayController property that I use to access the search bar, is also located in the de.lproj folder.
  • I set the development area inside .pbxproj to German:

     developmentRegion = de; 
  • I set the "localization localization development region" to "de" inside the Info.plist file:

     <key>CFBundleDevelopmentRegion</key> <string>de</string> 
+6
source share
3 answers

You can easily change the text of the UISearchBar placeholder by setting it as the placeholder property.

However, there are no simple interceptors to go to the cancel button.

How can you access the cancel button of the search bar by going through its views:

 UIButton *cancelButton = nil; for(UIView *subView in [searchBar subviews]) { if([subView isKindOfClass:[UIButton class]]) { cancelButton = (UIButton*)subView; [cancelButton setText:@"Abbrechen"]; } } 
0
source

I managed to solve this problem by hard coding the application language in the main function of the program, as suggested by this answer .

 int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[NSArray arrayWithObject:@"de_DE"] forKey:@"AppleLanguages"]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } 

This, however, solves the problem only if you have only one localization.

0
source

Your solution is enough, you do not need to mess with AppleLanguages.

If you took all the steps that you mentioned in your question, perhaps the problem was that you already had en.lproj on your device (or in the simulator) from previous collections. You need to remove the application from the device (or simulator), run Product > Clean in Xcode and install it again.

These are the steps that worked for me:

  • The project has only the de.lproj folder (no en.lproj).
  • Set developmentRegion = de; in project.pbxproj.
  • Set knownRegions = ( de, ); in project.pbxproj.
  • Set "Localization of the development area" to "de".
0
source

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


All Articles