I am trying to make my app localized. I have followed this procedure http://www.switchonthecode.com/tutorials/a-simple-localization-example-for-the-iphone. And have deleted all localization and done it over again. I've seen other tutorials with exactly the same procedure.
My view to localize is named InfoView.xib.
I have:
rigth-clicked InfoView.xib->Get info -> Make File Localizable
added Localization and named it to "sv" (for Swedish language)
edited the sv-xib
When the simulator is set to English or any other language, I do get the xib loaded and can present it. But when setting the simulator to Swedish language, the view is not instantiated.
When doing
NSLog(#"Language: %# ",[NSLocale preferredLanguages]);
I do get "sv" as the top language code.
("NSLog(#"Locale: %# ",localeString);" gives "sv_SE")
When trying this
[[NSBundle mainBundle] loadNibNamed:#"InfoView" owner:self options:nil];
NSLog(#"InfoView in loadView %#", infoView);
It prints "(null)" when simulator is set to "Swedish" but instanstiate with any other language.
This is my setting if I do Get info on my sv-xib, in case it matters:
I have done the cleant targets and did reset the simulator.
What can the problem be? And how is the mapping done between the name I choose when adding a locale (sv) and the simultar/device language setting? Is it the acutal "sv" I named my locale to that must match the device's language code ("sv" is one)?
And 30s after I posted this a thought struck me; "Why don't I check if the localized view in IB is linked to the outlet in my File's Owner"...
It wasn't... Perhaps the tutorials should mention that the new localized xib must be linked as well. And really, why isn't this done automatically...?
"Thank you Nicsoft!"
"You're welcome!"
Related
I want to dynamically change display name from within the application. Is there a way it? i dont want to use .plist. i want to use with xcode from application. Thanks
${PRODUCT_NAME} How can i call this value with code ?
The app name is defined in the app's info.plist file..
That come in Main Bundle..and iOS does not allow anything to be written and updated in Main Bundle..
So you cant programmatically change contents of app info.plist having app's name...bundle identifier ..etc
No, it's not possible. The Info.plist and everything in the app bundle is read-only once it's installed on an iPhone.
Add the following code to get the product name
NSDictionary *infoPList = [[NSBundle mainBundle] infoDictionary];
NSString *appName = [infoPList objectForKey:#"CFBundleDisplayName"];
appName is the value of "Bundle display name" or Product Name
I don't believe so.
You can localise it -- i.e., display different names depending on the language in use -- but I don't think you can change the name dynamically. That's probably a good thing... it could get pretty confusing if abused.
i m getting a problem with my localized xib.
I have created english version xib first, then made them localized, & added other localization.
it works fine in app also.
But when i open other language xib with IB, i m unable to get all outlets & IBActions.
It seems like it is taking only those one that were present when i created the localized file, & not showing newly added one.
Does file not getting updated?
Note : My other team member done the same thing & they don't have problem.
i also tried to removed & created all new localized file then also no change.
I m unable to identify the problem, i m stuck on this problem & cannot proceed with further development.
Please help .. :(
If you have Xibs in different languages, they don't get updated automatically when you change the English one.
Instead, you should either merge the new changes using ibtool (type man ibtool in Terminal to learn its options), or use a dedicated application like iLocalize.
In general, it can be quite an issue to update all the localizations all the time and sometimes large changes can't be merged well automatically. You need to be careful about that.
I am developing an application for the iPad. The application has following details:
Base SDK: 4.2
Deployment Target: 3.2
The application is a game application and it has got 10 rounds.
In each round I am loading 6 controllers and after the completion of each round again the same cycle starts.
The application works fine till 4 rounds but at the end of 4th round it crashes given following error:
"NSInternalInconsistencyException Could not load nib ind bundle:"
I have checked for everything solution like checking the nib file name, checking the nib file path. Nib file name and nib file path both are correct and targets are also correct but still it crashes.
Any help for this will be appreciated.
Thanks,
Shyam
Right click your nib file in xcode and make sure its type is 'file.xib'.
I had this problem too, in my case the cause was that my project had no localization to italian but the app was running under "it" settings.
The simulator has English as regional setting by default, everything was ok on it while the actual device had italian settings, so the app crashes immediately when attempting to load the RootViewController, because it was looking for an italian version of it.
In XCode I added an italian localized version to the RootViewController (now I see two entries under it, one for english created by default and italian). Note that you don't need to do the real translations in the view, it's enough that you create it and leave as default. Xcode copies all labels and text from the original view, you just leave as is for the moment.
You'll have to do this for each view controller in your project. Refer to Apple docs, for explanations on internationalization and localization here.
As a workaround, some people might prefer to change the device regional settings to English while performing tests...
i got button....
displays on button
Search...
when i selected localization.....
i need to display
Zoeken
for search button its displays Zoeken...
#All thanks in advance.
You should look at NSLocalizedStringWithDefaultValue:
NSString *buttonTitle = NSLocalizedStringWithDefaultValue(#"KEY", nil, [NSBundle mainBundle], #"VISIBLE_DESCRIPTION", #"DEVELOPER_DESCRIPTION");
[aButton setTitle:buttonTitle forState:UIControlState...];
You'll then need to provide the relevant localization files in your project for the languages you intended on targeting.
As a top level skim, you can create per-locale NIB and string resource files using the built-in internationalisation capabilites.
However, this is quite a broad topic (there's an entire section of the Apple developer site dedicated entirely to internationalisation, complete with sample code, etc.), so what you need to do it read the documents there, look at the sample code and then ask a more targeted question if you get stuck/have a specific issue.
How can I make UIBarbuttonItem localizable?
My implementation:
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(cancel)];
Originally I thought that it is automatic, because it looks easy to make it like this, but looks like not.
EDIT1: Official Apple dox says that cancel, done, edit, save buttons are localized, but not sure how to make it.
Alright, I think I know what's going on.
UIKit decides in which language to display strings, based on the value of [[NSBundle mainBundle] preferredLocalizations]. The idea behind this is to use translated resources whenever possible, falling back to English otherwise. For example, if you don't provide the translation of your app in Finnish and Finnish is selected in Settings->General->International->Language, your app will be in English. It may be a bit more complicated (UIKit may go through all the list of languages in the order displayed in Settings.app, trying to find the first language your app has translations for), but the point stands.
The above may be too obvious to miss a crucial nuance. The language determined by the above algorithm is used for the app's whole UI. For example, if the app bundle doesn't contain sk.lproj, nothing will be displayed in Slovak. In fact, it does make sense because otherwise some parts of UI would be in Slovak, other parts, in English.
Open the compiled app's bundle to see which *.lproj folders are there. The same set, sorted according to user preferences, will be returned by [[NSBundle mainBundle] preferredLocalizations]. All localizable strings, including system bar button items, will be displayed in one of those languages. If you don't support, for example, Russian, the whole UI will appear in another language, even if Russian is selected in Settings.app.
If this is the case with your app indeed, there are two right things and one wrong thing to do:
right: provide Slovak translation for each and every string displayed in your app, translate any text-containing nibs to Slovak too;
right: ignore Slovak altogether if you cannot (or don't need to) support it;
wrong: select any strings file or any nib, open Xcode's inspector, click "Add Localization…" (if the button is disabled, first click "Make File Localizable"), type "sk", click "Add" and build the project. This will make UIKit think your app is translated to Slovak, and system bar button items will automatically appear in Slovak when it's selected in Settings.app.
If you see a different behavior, there may be something wrong with the project/build/built app. For example, I noticed that when you make a file localized, its non-localized copy doesn't get deleted from the previously built app bundle.
Bump, but I think Vanya’s problem might be the “Localization native development region”/CFBundleDevelopmentRegion entry in Info.plist. If this is set to English and no localizations are explicitly made available as Costique explains, all system strings will be non-localized. But, set it to sk and - violà.
Not sure I understand your question correctly, but standard (system) bar button items are localized and thus automatically appear in the user-selected language. There are notable exceptions like UISwitch showing 0/1 instead of ON/OFF. What language are you having problems with?
That said, you can always use custom bar button items in place of system ones and provide necessary translations yourself. It's just overkill in most cases.
My implementation in Swift:
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonTapped(button:)))
This uses the system default language for "Done" text.