IOS 8.1 localization not working,only show key not value - ios

First of all,I did this follow this site http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014
I create a new Localizable.strings file,and localize it ,then add English and Japanese support.
I edit my Localizable.strings(en) file as follow:
"APPTITLE" = "Calibrate";
I edit my Localizable.strings(ja) file as follow:
"APPTITLE" = "こんにちわ";
At the source code,the early code :
self.title = #"PianoDisc Calibrate";
instead of :
self.title = NSLocalizedString(#"APPTITLE", nil);
Then I run it,But I get "APPTITLE" not "こんにちわ";
My environment is iPad mini,ios 8.1 system,Xcode 7 or 6.4. I'm also searched long time on the StackOverflow,like as NSLocalizedString only retrieves the key, not the value in Localizable.strings (IOS) ,I have tried the all answer,But it still not work.
There are some info,I use follow code,
NSString *path = [[NSBundle mainBundle] pathForResource:#"ja" ofType:#"lproj"];
NSLog(#"!!!!!!!!!!!!!!!!%#",path);
sometimes get null,sometimes get the true path.
What I'm missing? Thanks anyway!

I resolved it. Some guy remind that "check you haven't somehow messed up with the Build Rules (Xcode 4 -> select your target -> tab "Build Rules") There, check if you don't have too many "CopyStringsFile" rules that aren't using "CopyStringsFile". If so you can remove them all but one."
This step just resolve my problem,thanks god.

Related

Localization of the googleCast framework not working

I'm trying to find a way to localize the google cast sample app.
When I look at the documentation I see that we need to set some launch options when we create the sharedInstance. So in the sample app his appdelegate I changed the setSharedInstance part to this:
let options = GCKCastOptions(discoveryCriteria: GCKDiscoveryCriteria(applicationID: kReceiverAppID))
options.physicalVolumeButtonsWillControlDeviceVolume = true
let launchOptions = GCKLaunchOptions(languageCode: "fr", relaunchIfRunning: false)
options.launchOptions = launchOptions
GCKCastContext.setSharedInstanceWith(options)
I also tried fr-FR and other language codes and also tried to set 'relaunchIfRunning' to true. But It seems that none of that is working.
Anybody succeeded in changing the language of the googlecast screens?
Kind regards,
Stef
You must localize the Setting.bundle as well. And this is done manually using text edit :(
Settings.bundle:
Root.plist
en.lproj:
Root.strings
fr.lproj:
Root.strings
en.lproj, ru.lproj folders
Root.strings - file
Add the language in your project file, that worked for me.

How to get App name in UITesting swift 4 iOS

I tried to get my app name in UITesting. I tried the code below:
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
But it gives me the nil value result.
When I was trying to find out if the 'debugDescription' provides any information about the actual app (and not the test app) I stumbled across a label that looked exactly like the app's display name.
I don't know if it helps you, but the following simple line of code helped me:
XCUIApplication().label
Are you sure, that you've set Display name in your Info.plist file?
Just set this name in Project settings or in Info.plist:
Try to go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment.
Then click over the little grey arrow under Derived data section and select your project folder to delete it.
And Product > Clean.
It helps in many situations.
I am getting app name in UI test like this:
let app = XCUIApplication()
// ...
let appName = app.label

font awesome ios icons all the same

I'm trying to use FontAwesome on my ios app (ios8, xcode6), and am having trouble. I've downloaded the font, tried the TTF and OTF versions separately. I've included the font name in my plist file, and have included the NSString+FontAwesome and UIFont+FontAwesome categories that are standard out there.
The problem is that every font awesome symbol showing is always this same one. Everything works, it just never changes the character.
id github = [NSString fontAwesomeIconStringForEnum:FAGithub];
id twitter = [NSString fontAwesomeIconStringForEnum:FATwitter];
label1.font = [UIFont fontWithName:kFontAwesomeFamilyName size:32.f];
label1.text = [NSString stringWithFormat:#"%# %#", github, twitter];
If I use the unicode string directly instead of the helpers, it is still always the same
#"\uf001"
#"\uf002"
// etc
When I debugged the category classes and printed out the unicode array with all the font-awesome codes in the console, all the symbols were identical to the ones above.
[NSString fontAwesomeUnicodeStrings]
Has anyone seen this problem of the repeating symbol, or know a resolution?
EDIT
2 weeks later, after fixing by re-install: I believe the symbol shown is, which was always the same, is the result of the label's font either not being set correctly to FontAwesome, or the font not being loaded so it is not able to be set. That is the symbol that shows up when font is set to something like "System".
Steps taken for this to work:
File > Add File > Added ios-fontawesome in it entirety (copied folder)
Removed all .m files from fontawesome besides NSString+FontAwesome.m from compile sources
Added FontAwesome.tff to info.plist key Fonts Provided By Application
(Compiled for iPhone 5s Sim, 8.1 using XCode 6.1.1)
Test project listed here: https://github.com/spacedrabbit/StackScratchPad
As the comments indicate, this doesn't explain why it wasn't working it just is the way I was able to make it work.

Issue with localization in iOS

I have been stuck in a mysterious problem related to localization in the last two days.
I am trying to add languages to my app, but it seems to me that something is going wrong.
To make things simple, I added the following lines to my current app, to see if the word test will translate or not :
- (void)viewDidLoad
{ [super viewDidLoad];
UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.textColor=[UIColor blackColor];
[self.view addSubview:lbl1];
lbl1.text= NSLocalizedString(#"test", nil);
}
After adding the language in the section of localization in "Project info" section, and checking "Use based internationalization". In addition to creating "Localizable.strings" file and clicking on Localize to choose the language, the word test does not translate.
BTW, here is Localizable.strings file :
"test" = "test translated";
I've done clean, and deleted the app form my phone and build it again, but nothing changed !
I took the same code, and done the same steps by creating a new project on xCode, surprisingly it translates !
Anyone knows why the translation does NOT happen in my original app ?
Firstly, Base Internationalization is for storyboards, it is not for NSLocalizedString.
Secondly, the file should be Localizable.strings, not Localization.strings.
It happpened to me recently. I did those things:
1) Deleted app from simulator/iPhone
2) Cleaned app (Product -> Clean)
3) Deleted derived data (Window -> Organizer -> Projects (tab) -> (Select own project from left) -> Click "Delete..." on right of Derived data)
It helped me

iOS - NSLocalizedString is only returning the key string

I'm having some trouble debugging my NSLocalizedString implementation. Should be simple, but whatever I do, the function only returns the KEY string.
I'm using XCode 4.5 and iOS6, so I:
Added a new file called File.strings.
In my project settings I added English and Spanish as language settings.
Clicked "Make Localized" in the file inspector, and made sure that both English and Spanish options were selected, and also that the Target membership to my target was selected.
Added "KEY" = "TestEnglish"; to my english File.strings
Added "KEY" = "TestSpanish"; to my spanish File.strings
Added NSLog(#"Localization: %#\n", NSLocalizedString(#"KEY", nil)); to my .m file.
When I run the app, the value "KEY" is always displayed printed in the NSLog.
To jump into this a bit more, I tried this as well:
NSString *path = [[NSBundle mainBundle] pathForResource:#"en" ofType:#"lproj"];
NSString *str = [[NSBundle bundleWithPath:path] localizedStringForKey:#"KEY" value:#"" table:nil];
NSLog(#"Localization: %#\n", str);
and still the value "KEY" is printed, yet, path is a valid path.
Does anyone have any clue how to debug this? I feel like I've read every SO question/answer out there, but none of the suggestions help.
I realize that NSLocalizedString returns the KEY string when it cannot match a key, but I don't see how I can debug why my app might not be matching the KEY.
I've also deleted/cleaned the app about a dozen times.
If you specify table:nil, then NSBundle will try to fetch the localization from the default table (the one in SOMELANG.lproj/Localizable.strings). If you have the localization elsewhere, you should explicitly specify the table using table:#"File" (or use the NSLocalizedStringFromTable() macro in a similar manner:
NSString *value = NSLocalizedStringFromTable(#"key", #"File", nil);
Rename the InfoPlist.strings file to Localizable.strings (double clic) and then you will get the correct string for that key.
In my case the issue was with the case of the string:
"bla.bla.blabla.BookSlot" whereas the Localizable.strings had it defined as "bla.bla.blabla.Bookslot"
So, double-check that the key string is in the correct case. Better yet, copy-paste.

Resources