Problem with IPhone app Loacalization - iphone

I am developing an application for IPhone, and it need to be Localized for english (easy enough) and portuguese. My doubt is if we can only set the Localization for the xib files or if we can add the .m files to the localization too, because the .m files are always in the english version, while the Xib files are working as they should...
BEst regards.
Ps. I am Using XCode 4..

I can think of only one localizable resource in source code - strings. For these you have several variants of NSLocalizedString. Take a look at this manual Internationalization Programming Topics

You can localize the xibs fairly easily, you should also look at
[[NSBundle mainBundle] localizedStringForKey:Value:Table: ];
you can use this to pull the required string from the strings file,
which once you have generated you can manage with tools from http://www.loc-suite.org/
they make ongoing development and localization much easier.

Related

internationalization of an iPhone Application

I am new to iPhone App development (I am using XCode 4.2) and I was wondering if there is a way to translate all the strings , caption etc ... internally without having to translate them one by one .
an idea I have in mind is to use NSUserDefaults to save the language as a global variable and translate everything accordingly
another option is to make a look up table (is it even possible in Objective-C ?)
Thanks
You can use NSLocalizedString(#"<#key#>", #"<#comment#>") and one file (named Localizable.strings( per language. If you use the above function you can use the App Linguan (available on the Mac App Store) to generate the Localizable.strings files.
There is also a command line tool called genstrings that will create the file for you, but believe me that Linguan app will pay for itself in minutes.
You should always add a comment to allow a better translation and to provide context about the key.
You can read a step-by-step tutorial of the process here:
iPhone Localization Tutorial
Here's a high-level overview of the basics (the above tutorial has details):
1) Change all your coded strings to call: NSLocalizedString(#"My text", #"Context for the translator")
2) Export all your strings using the genstrings Terminal command.
3) This creates a text file called Localizable.strings with all your English (source) strings. It looks like this:
/* Context for the translator */
"My text" = "My text";
You send that file to the translators. They'll translate the right side like this: "My text" = "Mi texto";
4) You place each translated Localizable.strings file in its proper language folder: en.lproj, fr.lproj, es.lproj, etc.
When your app loads on the iPhone it will check the user's language settings. If the user has chosen French as the system language, the Localizable.strings inside your fr.lproj folder file will load. If there are any untranslated strings, it just defaults to English (or whatever your source language is) for those.
It's worth following the whole tutorial and note that the file/folder names have to be exact!
Look up the documentation for NSLocalizedString. And how to localize your .xib files (you make localized copies in English.lproj, de.lproj, fr.lproj, etc.).
All you will have to create are the files with the key-value pairs for each language you want to translate and name them accordingly i.e. _en, _fr and so on.
Then all you have to do is send a message to this method:
NSLocalizedString(#"myKey", nil)
And this will return the localized String, in whatever language the current iPhone configuration is.

iPhone wrong Localizable.strings used

I have a project with different Localizable.string files:
../en-GB.lproj
/Localizable.strings
../en-US.lproj
/Localizable.strings
../fr-FR.lproj
/Localizable.strings
../fr-CH.lproj
/Localizable.strings
etc... with about 10 different languages. All are UTF16 encoded. I use XCode4. When I configure my test iPod in fr-FR and launch my app the line:
NSLog(#"Current Locale: %#", [[NSLocale currentLocale] localeIdentifier]);
returns: Current Locale: fr_FR
But all my NSLocalizedString(#"my_string",nil) always return the values located in my Portugese localizable. Any clue for that problem?
Not sure if this applies to you, but i have noticed similar problems using ShareKit. It wasn't ShareKit's problem per se, but the problem involved localizable.strings files inside the library that overlapped mine (for example, I had 2 localizable.strings for the english language. One was mine, the other one was for sharekit).
The app was running, and was finding it difficult to decide which of the two localizable.strings file should it choose to draw strings from.
The solution was transferring all strings in one file end deleting the duplicate files, of course.
I hope I helped.
Firstly check your Scheme Options. You might have changed the "Application Region" which in above case maybe set to "Portugal". This should be set to "System Region" and "Application Language" to "System Language"
Make sure that you're dragging the localized files to their right folder. It's pretty easy to put in the wrong place.
Have a look here for the complete list of what you should do, including screenshots of where you should drag the translations in the project tree:
http://www.icanlocalize.com/site/tutorials/iphone-applications-localization-guide/
Try doing a clean and remove the app off the device/simulator and rebuild/deploy.
I have run into issues when adding new localisations and the device caching the app resources.
Also when I localise I tend to use the country code as the name for the .lproj folder eg.:
en.lproj
fr.lproj

iPhone support Multiple Languages

In my project, I need to support the Korean language. How is it possible - can anyone explain briefly with example, whether it is possible or not?
It's certainly possible.
You just tell Xcode to add a Korean localization to any of your application's localizable resources that need to change for that language. (Localizable resources include strings files, xib files, and potentially any images containing text.) Xcode will create a copy of your existing English resource, which you can modify and replace with a Korean-language equivalent.
Then when your application is run on a device with Korean set as its preferred language, iOS will automatically use the Korean resources intead of the English ones to present the application's user interface. If you have used good localization code practices (such as using NSLocalizedString to reference strings you present in the user interface) you shouldn't have to change any of your code to support different languages.
Check this guide on how to localize your apps for iPhone: http://www.icanlocalize.com/site/tutorials/iphone-applications-localization-guide/

iphone localization: retrieving a different file

i have an app that i have to localize. I am already localizing the nibs and some texts, i just have a doubt.
I need to pull a plist from the bundle which contains some texts, for the other languages i would have other plists. How can i accomplish the loading of them in a nice simple way.
My initial though is to have a text.plist , text-sp.plist , text-fr.plist and retrieving the current language then if language == english grab the text.plist, if language == spanish grab text-sp.plist and so on.
Is there a better way to do this?
I'd rather somehow make the .plist localizable and do something similar to what i do with texts using NSLocalizedString, but i am not sure how to use it in this case.
Sorry, just found the solution.
Just right click the .plist file and add new localizations like any other file. Then the OS handles which one to load according to the current locale settings.
I had to clean my targets in order for the changes to take effect, thats why i initially thought this was not working.

how to creating localizable.strings file by code in iPhone

I am working on one multilanguage project which will download string from server depend on language selected by user. I would like to save this downloaded string into localizable.string file. So how could I do that? I know how genstrings works but I would like to generated *.strings file by code and save it. My code will read this *.strings file for localizable. Anybody know which api i have to use?
thanks in advance
Manu
Typically, localization depends on strings files that are within the app bundle. Since you can not modify the app bundle at run time, you will have to put the strings files you downlaod elsewhere and you will have to modify the usual localization methods to find and use those strings files.
Look at Apple's iPhone samples to see how they do localization and fetching of the strings, and see if you can replace all the local accesses of the localization resources with resources in another directory.