Localization not working on Xcode - ios

I can't get my app to work with localization.
I have created a Localizable.strings file and ticked the languages that I am localizing. (For now I have base, english and spanish.)
Localized storyboard with three languages.
In Project settings > Info I checked Use Base internationalization and all languages are correctly added. (Moreover, beside the language it shows 2 Files Localized, which I guess they must be the storyboard and .strings file.
I am using this example for testing:
self.loginLabel.text = NSLocalizedString(#"login", #"Login text info");
This is how the Localizable.strings (Base) file is looking like:
"login" = "Log in";
However, it is not working and instead it is showing login. Have I forgotten a key step?
BTW: I have tried already changing the login text just it case something was overriding the label.

Those are the steps indeed, I don't think you've left anything out. I usually set the comment to nil instead of another NSString though - not sure if that makes a difference.
However, rather than in only base, make sure you're adding the same line also to the English and Spanish files (obviously translated as appropriate).
Next, for the language to show up, set the device to said language. Close your app and start it again. Strings should now show up in the other language.
Note that the Simulator often has trouble with new translations, especially when they've been added to an already deployed app. In that case, remove the app from the Simulator, click on Product - Clean, and re-deploy.

In my case, it didn't work because the UILabel text was set as "Attributed" instead of "Plain" in the Attributes Inspector.
Localization with a .strings file doesn't seem to work on Attributed strings.
I even had a storyboard with mixed Plain and Attributed string labels, and the localization only worked on the Plain ones.

For anyone having a similar issue in the future:
Check if your *.strings file has any non-printed characters.
I used JavaScript for a simple task and didn't realize it included some whitespace characters.
An easy way to check is to put the translation at the top of the file and see if it works. If it does, there might be some whitespace characters. The next steps are... binary search and remove the whitespace characters.

Related

Internationalise Authorisation Sentence in XCode

I want to internationalise the comment used to give more details about a required authorisation.
My whole project already use a Localizable.strings and everything works fine.
But I can't get to make it works with these sentences located here:
Am I missing something here? I already tried to add a simple word, that is translated in the Localizable.strings but no effects on it so far :(

German localized string appears in English

My problem is very odd. I am developing an app in 6 different languages (including English and German) and I have localized every single string within the project. Therefore, some texts in the app display in English instead of German.
This happens only for German and always for the same texts. I have run a search of the English strings that shouldn't appear and it is only in English localization files (base files). I clean the project, checked the IDs of the Labels, and anything else. Nothing worked...
Did someone went into a similar issue ?
EDIT: If I try playing with ordering my strings in the German strings file, then I can get the right translations ! But some others won't work anymore.... It looks like a big bug from xCode but it's totally messing up all the project !
Please check you file with your localised strings in German and check that keys are the same you asked in LocalizedString() for that labels.
It happens when LocalazedString doesn't find string for German locale and return it for default locale (English).
Finally found it. It appears that a character has been somehow inserted in the end of a commented line. This character then appears as a comment in xCode, but it is not. Finally, at runtime all translations in lines after this unwanted token will be ignored.
xCode will not help you nor give any warning about it....

iOS App Localisation Best Practices And Placeholders

We're currently at the stage of looking at localising our app in to multiple languages now that the general concepts of the app have been decided. This is something I want to ensure is done correct from the start to lower the risk of headaches in the future.
The app targets iOS 7 and above, uses storyboards, and is written in Swift.
Storyboards
When working with a storyboard (or a xib), what's the best way to mark a UI element as "not to be translated"? For example, I have a placeholder string for a user's display name (Display Name), which will be replaced by a users display name at run time. This display name will not be localised, but neither should the string "Display Name". Is there a method of not having a UI element's value automatically put in to the strings file? If not, is going in to that file and manually removing strings I don't want localising a sustainable option?
Strings In Code
I'm using the Swift function NSLocalizedString with the key and comment parameters. Some places I've seen say to set the key to be a unique id based on the context (e.g., intro.login-button-text), while others seem to just put the full string in the default language (e.g., Login). I like the idea of the unique ids for the key, but would this not go against the idea of the "base" language?
Exporting
Xcode 6's "Export For Localization" option seems very useful for getting the correct format of file to be sent to translators. However, as mentioned previously, placeholder text does not need to be translated. Should these placeholders be removed from the exported xliff or the strings file prior to export?
Looking for the the same questions myself. Hope this will help you and others. Also I would recommend to have some kind of tool to organize the xliff/string files
Storyboards:
I've seen developers putting non translating texts in storyboard with extra parentheses. i.e. {Display name}.
By using this you can see by the translation itself if it needs to be translated or not. We use oneskyapp.com and can select to hide those translations and they will be hidden for each import of that key.
Strings in Code
By following this thread they suggest to use keywords.
Best practice for key values in translation files
Exporting
I cannot find a way to have some translations automatically removed when exporting. Off course you can put the views which has dynamic fields in different XIB/storyboards and decide not to translate those.
Again a tool like onskyapp.com can help you with this.
Formats
As of context with the field is important and a translation can be different when it is followed by i.e. a users name I would go for "%1$# is online!"

What would be the most efficient way to add these text files to the code?

I have been trying to create a font type app that changes how the original text looks using emoji styles and uni-code. To create these "fonts" all the letters need to be attached to every key from A-Z to apply the desired effect. There is a few ways to do this i have seen. in a .txt format and a .plist format. Im using a .plist to link every single keyboard letter with a new letter which includes both lower case and capitol letters. This method would just take forever and is very tedious, so i was wondering if there is an easier way. There are apps that have over 100 fonts, so if you did the math, that's just a very long time to just copy/paste every letter 52 times for every font. Please help with any suggestions. Thank you! you will save me lots of time!
Example app that does what mine will do: https://itunes.apple.com/us/app/better-fonts-free-cool-new/id735011588?mt=8
example of changing every letter and my setup:
I would recommend finding the font you want on the in internet and then importing it into your project like a .ttf file. Then you can just change the text to this specific font... simple. If you still needed some fonts that use emojis or whatever and you can not find the font on the internet, you are just going to have hunker down and do the plist files. :)

Localization for a very simple app.. How to connect a button?

I have a very simple app which only contains a PickerView, UILocalNotification, UIAlertview and less than 8 views. What I want is:
I have a main view which contains two buttons one says English and the other says French.
What in my mind is:
When the user hits English it'll take him to the Project I have right now,
However, when the User hits French it'll take him to a duplicated views that I'd simply and manually change and translate it's labels into French.
** Now my question is ** how do I translate the PickerView, LocalNotification and the AlertView? and how to connect the French button to these translations?
From what I've googled and read here in SO is that I can get the strings out and list them into Localizable.strings but I still don't know how to make my french button ask for these strings? Also, is there an easier and simpler way? any idea?
Thanks,
Kindly try this for doing localization
http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial
For buttons use something like this
[self.yourButton setTitle:NSLocalizedString(#"YOUR_KEY", #"Comment") forState:UIControlStateNormal];
Do not duplicate your views and view controller just for the sake of localization, considering that for both languages have the same layout and everything only thing that would change is the language. So add English strings and French strings to your project and use NSLocalizedString to get these values.
Note:NSLocalizedString works with device language only so if you want to change the app's language manually try this. I have used AMLocalizedString in many of my projects and they work fine.
Hi as you want to make it localized only at App basis not at device basis hence NSLocalisedString will not work you have to manage it so you have to take two different files and you have to fetch the string value on the basis of selected language. In similar manner as LocalisedString works as in localization there are multiple .strings file created for languages and it works in a way to select default language of the device and shows the text from the localised file.

Resources