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**"**;
Related
I have localized my iOS application in French and English now
I want to add German language in my project.
For NSlocalized string I have created a localizable file for French, how can I create another localizable file for German languages,i am using this code for localizing strings
NSLocalizedString("ReJoin Now", tableName: nil, bundle: Bundle.main, value: "", comment: "")
I added a Localizable.strings to my project, but its not working... Here is a sample:
NSLog(#"Welcome Text: %#", NSLocalizedString(#"WelcomeKey", #""));
The Localizable.strings:
Localizable.strings // DE
"WelcomeKey" = "Willkommen!";
and
Localizable.strings // EN
"WelcomeKey" = "Welcome!";
The Localization native development region is en
The NSLog in console is:
2013-05-11 04:45:49.552 App[13752:907] Welcome Text: WelcomeKey
Any ideas what's wrong ?
The localization from the Storyboard is working.
Codierung of both files are UTF-16
Have you added a strings file to store the localized text. Click File > New > New File.
This link will be helpful to you. Please check this localizable strings.
I found this answer maybe helpful to you:
Select the localized storyboard eg. Chinese (Simplified)
In File Inspector, toggle from “Localizable Strings” to “Interface Builder Cocoa Touch Storyboard”. This will retain the strings you already had, so you don’t have to worry.
Now, change it back to “Localizable Strings”, and things should be updated!
Here to view original tutorial
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.
I'm currently localizing my iOS-Application. This works pretty decent so far.
I've already created localizable.strings and several xib-files and so about 80% of the app is already translated.
But the App also loads data from a WebService which passes me a key, e.g.: "TITEL 1" as well as all supported languages (values) attached to it e.g: "Titel One" "Titel Eins" "Titolo Uno".
And now i would like to store those values in the according localizable.strings files.
For example:
Localizable.strings (English) should then contain:
"TITLE 1" = "Title One";
Localizable.strings (German) should then contain:
"TITLE 1" = "Titel Eins";
Localizable.strings (Italian) should then contain:
"TITLE 1" = "Titolo Uno";
How can I do this?
You will not be able to insert them in the localization strings at run time, if the webserver is managed by you, i suggest that you send wich language is the user using,
Please consider this example
//Get the language code
NSString* languageCode = [[NSLocale preferredLanguages] objectAtIndex:0];
//Now send the request to the server with the language you want
NSString *str = [NSString stringWithFormat:#"www.yourserve.com/yourfunctiom?lang=%#", languageCode];
//Request it
Now basing on the language that you receive in your server you will return the appropriate string
This may be stretching the frameworks a bit, but if you want to use Apple's string loading functions you could try to build an NSBundle in your document directory (a bundle is just a directory, after all), fill it with files from the server and then use NSLocalizedStringFromTableInBundle to get to your strings.
Not sure it is worth it compared to the approach in Omar Abdelhafith's answer, though.
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