Trouble localizing iOS application, clarification needed - ios

Please let me know what in the following sequence is incorrect.
Somewhere in code, i have self.label.text = NSLocalizedString(#"TITLE", nil);
Localizable.strings created ( new -> Resource -> String file)
Localizable.strings (English) created // contains "TITLE" = "Hello";
Localizable.strings (Russian) created // contains "TITLE" = "Привет";
Simulator started and application deployed
Xcode closed
Simulator settings changed from English to Russian (Settings -> General -> International -> Language -> Russian)
Xcode opened
Application deployed (icon labels appear in Russian) .. when ran it says "Hello" instead of "Привет"
Am i missing a step? Did i do something in the wrong order? Please let me know

Those steps look fine. Things to try:
The folder name for Russian needs to match the language code
(ru.lproj -> Localizable.strings)
Check that the label is hooked up properly (if you're using interface builder) and not nil when you are setting self.label.text

Related

NSLocalizedString always returns capitalized text

Ive run into an issue where NSLocalizedString is always returning strings capitalized regardless of its input. localization was working
and Im assuming I did something that caused this but I cannot seem
to figure out exactly what changed.
Here's my code:
func localize(_ str: String) -> String {
print("str in: \(str)")
return NSLocalizedString(str, comment: "")
}
I call it like this:
let txt = self.localize("Question")
print("txt = \(txt)")
Output:
str in: Question
txt = QUESTION
Things Ive tried:
Ive grep'd all of my .strings files and confirmed there is no
'QUESTION' in there.
Removed app from Simulator and re-run app
Changed incoming string to something that doesn't exist in any file such as 'randomxxyxxy'
Ive tried searching for quite a while on this issue and wasn't able to find anything that was like this problem.
Any help is appreciated,
Thank you
When your app is trying to localize a string but cannot find the translated text for it then it will show it in capitals. This is done to show you that the capitalized text is not localized. You can disable the capitalization of those cases by disabling the option: Show not-localized strings
This is how you do that:
Edit the scheme
Select the “Run” action and click the “Options” tab
Uncheck the “Show non-localized strings” option
In your case I think that your strings' localization is not working and so they are capitalized because that setting is activated.

iOS - only one localization works

I try to localize my project. I have clicked "Use Base Internalization" and added 2 languages: English and French. The English is marked as "Development language" - not sure, maybe I set it, but in the storyboard I use another language (not English). And second difference between these 2 localizations is that English (Development language) has 2 files localized while French has only 1 file localized (screenshot) I checked the app's folder. In the en.lproj
there is only 1 file Main.strings with all my english translations. In the fr.lproj the same thing - only Main.strings but with french translations.
So in the folders everything is correct, but:
1) When I run app with English language - everything works correct. But when I set French language to simulator (or my real device, after deleting the app) nothing works - it shows me my standard storyboard (not English).
2) English localization has 2 localized and I can't understand what is the second file.
The second point is not crucial for me now. I just need to make French localization work
When you add Localization than these file will show
Localizable.strings (English). “Hello ” = “Hello”; (Ex you can write hello )
Localizable.strings (Frech). “Hello ” = “Bonjour”;
Or main string you can change object into freach
Main.strings(English). 3ZR-e4-Gil.text" = "Hello";
Main.strings(Frech). 3ZR-e4-Gil.text" = "Bonjour";
swift
import Foundation
extension String {
func localized(lang:String) -> String {
let path = Bundle.main.path(forResource: lang, ofType: "lproj")
let bundle = Bundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}
}
let str = "Hello".localized(lang: self.language! )
change language via simulator
Or Programmatically change language via app
UserDefaults.standard.set(["en","fr"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
SOLVED IT!!! The French localization wasn't used because there was a mistake in the Main.strings (for French) - I missed only one ("). But as in the Main.strings there is no catcher for such a mistakes I didn't get it.
So, it was: "XXX-6r-aEC.text" = "Confirmer;
and I changed it to:"XXX-6r-aEC.text" = "Confirmer**"**;

Adding localized string to UITextView in swift

I am following the instructions on this blog post to localize my swift app. http://evgenii.com/blog/localizing-text-in-swift/
In my Swift file I have
let my_interests = "Reading: Children's books, biographies, history and science fiction.\n\nProgramming Languages: Learning new programming languages."
....
textView.text = NSLocalizedString("my_interests", comment: "Just a Test")
When I go to the Editor and select Export For Localization
I get an error.
You probably don't have a Localizable.strings in your project.
In your XCode project go to File -> New -> File -> iOS -> Resource -> Strings.file -> Next
Name the file Localizable.strings

why is my IOS app title (under icon) not appearing localized?

I'm using Corona SDK but was hoping for some advice here, as I'm hoping someone can spot my error. I am trying to get the app title that appears under the icon localized.
I'm doing the following (in Corona SDK) this but I'm still not seeing the app title change under the icon when I change the "LANGUAGE" setting of my iPhone.
a) put CFBundleLocalizations in build.settings per below
settings = {
iphone =
{
plist =
{
CFBundleIconFile = "Icon.png",
CFBundleIconFiles = { << cut for this put >>},
CFBundleLocalizations = {
"English",
"French",
"Japanese",
"Chinese",
},
},
},
b) put a 'InfoPlist.strings' file for each language in a directory like 'fr.lproj' under the root. In the strings file put:
CFBundleDisplayName = “Parachutiste”;
QUESTION: Any advice or do you spot an error in what I'm doing. I must be either (a) missing something here or (b) misunderstanding how to test a change of language on my iPhone to test this? (i.e. I'm currently assuming I just change the language of the phone and this should trigger a different app title to appear under the icon)

NSLocalizedString is it really working?

I misunderstand NSLocalizedString.
I have a project with French and English .strings files.
In project target - Localizations I have 6 files in French and English.
In english.strings file:
"hello" = "world";
In french.strings file:
"hello" = "salut";
When I write a simple line of code to change label text:
exerciseDescription.text = NSLocalizedString(#"hello", #"no comment");
Output is: hello
I changed in iOS simulator : settings - general - international - language - French/English - Done
And output is again: hello
I thought it should be world or salut...
You're using it in correct way but not added properly,
Localized filename should always be named Localizable.strings, and that file is within the particular language folder, for English, en.lproj and for French fr.lproj like wise.
You are using it right, but as #Hemang mentioned you should change your filename to Localizable.strings as this is the default.
Furthermore I would like to suggest cleaning the build folder, and removing the application from the simulator. That helped for me in one case.

Resources