This app has been under development for more than a year and has had multiple releases already. This development cycle I noticed that the "fallback" language doesn't seem to work anymore.
The app had 3 targets: CountryA, CountryB and CountryC.
Each target has the following localization directories:
CountryA: en.lproj, langA.lproj, langB.lproj
CountryB: en.lproj
CountryC: en.lproj, langC.lproj
In each targets info.plist a key "CFBundleDevelopmentRegion" with value "en" is specified.
The project.pbxproj file has both the following key/values specified in the PBXProject section:
developmentRegion = en;
knownRegions = (
English,
Japanese,
French,
German,
en,
fr,
dk,
da,
nl,
new,
pt,
de,
);
When I start the app on an iPhone or in the iPhone simulator with the system language set different from one of the specified localization directories the UI shows the NSLozalizedString identifiers instead of the localized strings. Even when I specify "English" as System Language in iOS!
So... for some reason the en.lproj file is not picked up, because if I use langA or langB as System Language for target CountryA everything is as expected.
Any help is appreciated!
Kind regards,
Niels R.
NOTE: The problem is caused by a plugin of an external company that we had to integrate and which has a Localizable.strings file too. This will cause that "our" Localizable.strings is overwritten.
Sorry to bother with this! Seems that I just had to look a little bit further before asking the question.
"the UI shows the NSLozalizedString identifiers instead of the localized strings" -- Are you adding the Localizable.strings file correctly for the individual targets?
Another problem could be the "region" setting for languages. You should try to change the region too in the Simulator. I have seen unexpected things happening to NSLocale when setting the region to something totally different than the language.
Related
I'm quite new to the world of google home/assistant, but I've tried out the new Actions builder, which seems really good and intuitive. I have added the methods of invocation, an intent that triggers an inline webhook function, and filled out all the mandatory fields under "Deploy" for both languages. Testing works as expected in simulation (except not in my native language, Norwegian).
But when I try to create an alpha release, it says "Missing info", and that i should navigate to the "Overview" to see what's missing.
I head over to the overview only to see that multiple things are missing (in both English and Norwegian). Like "Decide how your Action is invoked" under "Quick setup".
I click on the link, which brings me to settings:
There I can "Edit main invocation handling", which brings med further to the main invocation screen:
As far as I can tell, everything about main invocation is in order, or is it something I'm not seeing here? It also says that there are missing information required for the action directory, among other things for the Norwegian language, that are also present.
PS: Pardon any misspellings, English is not my native language.
UPDATE: As for the English language, it was the name that caused the troubles. "My medicines" contained "My", that apparently don't count, which then caused the name to result to "Medicines", and it's not allowed with single word names. After solving this, I was able to create a release for the English language. But I'm still not sure how to deal with the Norwegian language tho.
UPDATE 2: I ended up just removing Norwegian from the Language settings, and adding it again. Then refilling the mandatory fields and translations. Then it worked!
For the English language, it was the name that caused the troubles. "My medicines" contained "My", that apparently don't count, which then caused the name to result to "Medicines", and it's not allowed with single word names. After solving this, I was able to create a release for the English language.
I was still unable to create a release for the Norwegian language, so I ended up just removing Norwegian from the Language settings, and adding it again. Then refilling the mandatory fields and translations. Then it worked!I was able to create and release in both my languages.
Can anyone provide a pointer to an updated tutorial/example of setting up custom file associations on iOS using Xcode 4.3?
I've seen the following (including Brad Larson's excellent answer), but the handling of Info.plist in Xcode 4.3 is significantly different than any description I've seen:
How do I associate file types with an iPhone application?
Importing/Exporting Documents on iOS
How to register an app to respond to a custom URL scheme opening request?
I tried reviewing Apple's documentation, but "Document Interaction Programming Topics for iOS" was updated in Nov-2010.
None of the examples I can find discuss configuring it in the way Xcode 4.3 handles them - which includes separate "Document Type", "Exported UTIs", "Imported UTIs", and "URL Types" sections under the target/Build Info and includes different key names (e.g. "Description" vs. "UTTypeDescription")
Any pointers are helpful, a working Xcode 4.3 example would be fantastic.
Based on suggestions by #samson but I wanted to capture this answer for future searchers.
Find the info.plist in the Project Navigator. Mine was under a "Supporting Files" group prepended by the application name (e.g. MyApp-Info.plist). Right-click and "Open As > Property List".
Then by entering the described sections as follows I was able to be passed a fileURL from Mail:
I should note a couple things for the record:
I did NOT put document icons for my file type, but it would be strongly encouraged to do so.
The property editor will try to auto-complete the names of properties, so it really gives you quite a bit more guidance than is apparent.
I search around the web, but I can't find the answer, maybe this question is too simple.
In the app I developed, how to display those default items, such as back BarButtonItem, ImagePicker buttons, or in the UITextView, the pop-up menu with copy, paste, cut, replace and select all, I can't figure out how to display these items in other language, for example, Chinese, Japanese etc.
Thanks.
Attribute in *-Info.plist "Localization native development region" is responsible for another thing.
CFBundleDevelopmentRegion (String - iOS, Mac OS X) specifies the native region for the bundle. This key contains a string value that usually corresponds to the native language of the person who wrote the bundle. The language specified by this value is used as the default language if a resource cannot be located for the user’s preferred region or language.
(Source)
Solutions:
In my app I have custom localization (not standard mechanism with *.lproj). And to say the system that I can handle localization manually with some languages, I set the CFBundleLocalizations (in Xcode "Localizations"). It's array property where you can specify handled languages. In Xcode could be problems to set Localizations attribute to type 'array', solution here.
CFBundleLocalizations (Array - iOS, Mac OS X) identifies the localizations handled manually by your application. If your executable is unbundled or does not use the existing bundle localization mechanism, you can include this key to specify the localizations your application does handle.
Each entry in this property’s array is a string identifying the language name or ISO language designator of the supported localization.
(Source)
UIKit is a framework and has localized resources (such pop-up menu of uitextfield). In Bundle settings(*-Info.plist) you can set CFBundleAllowMixedLocalizations (set to YES) to retrieve those resources.
CFBundleAllowMixedLocalizations (Boolean - iOS, Mac OS X) specifies whether the bundle supports the retrieval of localized strings from frameworks. This key is used primarily by Foundation tools that link to other system frameworks and want to retrieve localized resources from those frameworks.
(Source)
Read up on the internationalization technology:
http://developer.apple.com/internationalization/
In particular, the thing you're talking about is known as "Localization".
I just found this tutorial via google:
http://www.switchonthecode.com/tutorials/a-simple-localization-example-for-the-iphone
N.B. "internationalization" is sometimes written as "I18N" because it is such a long word! (Weird acronym, but it's because the word is an 'I' followed by 18 letters and then an 'N')
I wrote a tutorial on this where I stepped through how to do this (based on an application I localized in six languages):
Developing localized iPhone applications
http://www.pushplay.net/2009/08/developing-localized-iphone-applications/
I also described some of the language/idiom issues I was dealing with, which might be useful to keep in mind. There is the technical problem of how to implement multiple languages, but there is also the communication problem of having things be nonsensical when directly translated out of context...
EDIT: to respond to your comment, I'd still do it the same way (localizing everything). If not, set it up to localize anyway, but only translate the specific strings you want (and leave the rest as English).
If you really want to do everything yourself, you can do this:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:#"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
Then you can compare the currentLanguage variable and display the proper text in an if/then/else if/etc code block. I'd probably recommend having an "else display in english" at the end of the code block, just in case the language returned is different from what you were expecting.
EDIT: I just re-read what you were asking, and realized you meant localizing system functions. That's not something you can control -- when a user goes into their Settings and changes their language, all of those system interfaces (like "Cut/Copy/Paste") will automatically be localized. As long as they set their proper language in their Settings, that should work automatically.
I want to make the language changeable from the application settings. For that I made a settings.bundle and i forced the langauge using this code How to force NSLocalizedString to use a specific language , I also put the UIApplicationExitsOnSuspend to YES to make my app reload every time it goes to the background.
It partially worked for me but I have 2 problems :
- The splash screen (which is localized) is not changing with this method.
- I must enter/goBack twice to make the language change effective on the application Views an this only on the OS 4 and higher.
Has anyone a solution for that?
You need to create you own translation framework for that ! Sorry !
Unfortunately there's no built-in way. What would be probably easiest would be integrate service like GetLocalization.com, so that your app would download language file via API (then it's easy to add new languages and translations even app is already released). Then what you need is just simple loader that loads that language file to memory and function that replaces the original string with translated one in run-time. You can calculate hash for original string so it's fast to search them, good algorithm for this is Peter Weinberger's hashPJW.
The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,
here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps
I'm working on a localized app and everything is working fine. The problem is I want to allow the user to specifically select the lenguage for the specific app, in the app settings folder. This should users that their phone is set to one language (e.g. french) to set the app to work in English.
I'm currently using NSLocalizedString to get localized string but looking through all variation of the macro I can't find one that will let me specify the language.
Any ideas on how to do it?
There are three issues here:
Strings
Other resources (including NIBs)
System messages
The last is almost certainly not fixable, so we will leave it be. They're going to show up in the device language.
The other two are solvable, but you will need to do more things by hand. For strings, instead of creating a single Localizable.strings and then localizing it, create completely separate tables (English.strings, French.strings, etc.) Then, use NSLocalizedStringFromTable(), passing the language as the table.
For NIBs, there are two approaches. You can put each set of localized NIBs into its own Bundle and then pass that Bundle rather than nil to -initWithNibName:bundle:. Alternately, you can hand-load the NIBs after finding them with [NSBundle -pathForResource:ofType:inDirectory:forLocalization:].
There is a better way to do this. You can force the language like so:
[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:#"en", nil] forKey:#"AppleLanguages"];
And undo this setting by:
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"AppleLanguages"];
NB. you will normally have to restart the app for this to take affect.
Consider if you need to call [[NSUserDefaults standardUserDefaults] synchronize];
I agree there is little need to allow the user to specify a language. However the one exception is being able to override the language and set it to the developer's native language. If the user can speak the developer's language (e.g. English for me) then they may wish to use the App in that language, if the translations are incorrect.
I reference this answer: How to force NSLocalizedString to use a specific language (the answer doesn't actually work for me, but following the ideas in the comments did. The undo stuff I worked out.
The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,
here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps
The correct "User experience" is for the user to select their language via the system preference panel; not your app (or your app's settings panel, etc.). There is no way to override this per-app and we wouldn't want any app changing the system wide setting.