My localized strings are not detected - objective-c

I'm trying to localize my strings in Xcode 4, but the only thing I get are the keys, not the values.
I've localized the strings using NSLocalizedString(key, comment).
I've generated the file Localizable.strings using genstrings from the command line.
I've dragged and dropped Localizable.strings from Finder to Xcode (into the Resources folder).
I've localized Localizable.strings and added the appropriate countries.
I've made sure the encoding is UTF-16.
I've translated the different Localizable.strings for each country.
I've rechecked that the encoding is still UTF-16.
I've checked that each statement in Localizable.strings ends with a semi colon.
Still not working.
Any idea of what I've missed?
edit
Here a part of my Localizable.strings
/* Text displayed on the comment button if there are more than one comment. */
"CommentButtonTextPlural" = "comments";
/* Text displayed on the comment button if there is exacly one comment. */
"CommentButtonTextSingular" = "comment";
/* Text displayed on the post button. */
"CommentViewPostButtonLabel" = "Post";
/* Default text displayed in the area where the user types in a comment. */
"CommentViewWriteAComment" = "Write a comment...";
/* Error message explaining that a document isn't viewable on the user's device. */
"DocumentRendererStatusDetailedErrorText" = "This document is not viewable on this device.";
/* Message explaining that the document is downloading. */
"DocumentRendererStatusDownloadingText" = "Downloading...";

You may be putting the Localizable.strings file in the wrong location so it's using the default translations.
When you add a new language, Xcode creates a new folder in your App Directory which ends in .lproj (so for English it would be en.lproj) and that is where your Localizable.strings file for English should be.
If you want a French one, add the French Language and Xcode will generate a fr.lproj directory and that is where the French Localizable.strings file will be located.
From your description, putting it in the Resources Folder is incorrect.

Your Localization should look like the following:
and on your desktop:

I managed to get it working.
What I did was remove the Localizable.strings (from the harddrive, I haven't touched the files located in the xx.lproj folders) file which genstrings created for me and removed the app-file on my device.

Related

Intellilj Idea TODO search space to include other file types, e.g. .md and .asciidoc

IntelliJ Idea does not seem to be searching thru .md and .asciidoc files.
I'd like to maintain a list of 'TODO's in such files (because we can add more, well-formatted-for-readability information in such files).
If I change the file extension to .txt then the TODOs appear in the TODO tool window, but if I change it back to the .md or .asciidoc the TODOs disappear.
Is there a way to configure the scope of the TODO search algorithm in Idea?
The present TODO setup window allows us to configure the search pattern and the filters for pruning the tool window display list. It does not allow us to extend the search space of the TODO list to other file types in the project space.
JetBrains docs state
These patterns can be used inside line and block comments of any supported file type.
Markdown is a supported file type (looking at v2019.3.3), so what's the problem?
The problem is that markdown files do not support either line comments nor block comments.
As of today TODO works fine in md, adoc and txt file. Thanks.
TODO recognition is provided by the plugins supporting each file type. If you install the Markdown Support and AsciiDoc plugins, you should get correct TODO display for those file types.

Localizing the Cut|Copy|Paste menu on iOS

Im having some issues localizing a danish app ive made. (The language, not the pastry)
I have set the CFBundleDevelopmentRegion to da_DK for danish in my info.plist, but the popup appearing for text input is still in english, even on phones running the danish OS.
How in Jobs name can i change this ?
The test device is a non-jailbroken iPhone 4S running iOS 5.1 with Danish as its iOS setting, and a danish itunes account associated.
I do not use .xibs for designs. all interfaces are programmed as viewcontrollers.
In the Xcode's file tree (Project Navigator) select your project. in the right hand pane select your project again. select Info and add your language.
I created a sample project, this is the result:
You can do this directly in the info.plist. Something like this:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
<string>es</string>
<string>ja</string>
</array>
Try adding/setting the "Localized resources can be mixed" flag in Info.plist to YES.
You must localize your app in Danish to make the standard UI elements appear in that language. This is to avoid having a UI with mixed languages.
If you don't use xibs, you'd usually do this by adding a Localizable.strings file to your project. In Xcode's "Add File" dialog, you can use the "Strings File" template (under "Resources") for this.
To actually localize the strings file, open the file inspector (⌘ ⌥ 1) and click the + button in the "Localization" section. You'll end up with the file being displayed as a group in the project navigator, with a sub-entry for each language.
The strings file has the format:
"Label_Text" = "Smørrebrød";
(don't forget the semicolon)
To use localized strings in your code, you can use the NSLocalizedString macro like this:
myLabel.text = NSLocalizedString(#"Label_Text", nil);
(The second parameter is for a comment. This can be useful if you use the genstrings tool to extract localizable strings from your code and give the resulting file to a professional translator.)
If you use the English strings as keys, you can leave the English version of Localizable.strings empty (but don't delete it).
Having a Localizable.strings file in the language that the user has selected will also cause standard UI elements, such as the editing menu, photo picker, and so forth, to appear in that language.
If you can't get it working the official way, as provided by #vikingosegundo, you can do this with some creative engineering (Creative as in, oh my god that is dangerous). I discovered this method when I accidentally overrode [NSBundle localizedStringForKey:value:tableName:].
1) Add a category to NSBundle with the following methods:
#import <objc/runtime.h>
+ (void) load {
Method original, swizzled;
original = class_getInstanceMethod(self, #selector(localizedStringForKey:value:table:));
swizzled = class_getInstanceMethod(self, #selector(swizzled_localizedStringForKey:value:table:));
method_exchangeImplementations(original, swizzled);
}
- (NSString*) swizzled_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {
NSLog(#"Key: %#. Value: %#", key, value);
return [self swizzled_localizedStringForKey: key value:value table:tableName];
}
2) Where I simply log the key/value, you want to put an if ([key isEqualToString: xxx] ) block. In there, you want to catch (at least some of) the following key values: Cut, Copy[Menu], Select, Select All, Paste, Delete[Menu], Replace..., Define, Speak, Pause. These are the default values that can appear there.
3) When you have caught the value you can look up in a custom table or use hardcoded values. If you look up in a custom table make sure you have a catch in your swizzled method to avoid infinite looping in your custom table.
NB: Why do you need to swizzle? Because this over-rides all Apple text for you app. You will still want the defaults for all the other strings, so you need to swizzle to get the defaults for the strings you aren't interested in.
Good luck.
Paul
Search if your .xib is localized (you'll find it in the inspector on the right panel) if so go to your Project/Target-Settings press the +-Sign and select "Duplicate English to Danish" or something which means the same (I can't check the right item at the moment)
Btw it's called iPhone 4S.

Multilanguage application and .string file

I'm looking at some example of using NSLocalizedString and there is a .string file in project where i can find:
"Loading" = "Wczytuję...";
And then in a app code i can find:
return NSLocalizedString(#"Loading", #"");
How can i create multilanguage version of my app using that? Or there is a other way?
I want to have button to change language.
That's exactly how you localize an iOS app. Everywhere where you want to show some localized text you write NSLocalizedString(#"Something", #"Optional Description"). Then you add a file called Localized.strings to your app's resources and translate the text there:
"Something" = "Something in other language";
You can add new languages by selecting the .strings file and on the right side of XCode add a new language:
You can also have additional, separate .strings files in your project. Then you have to specify where to look for a translation: NSLocalizedStringFromTable(string, filename, comment)

.lproj and Localizable.strings : project with localized text?

i was reading the doc about localization and internationalization , but it's not really clear for me : can you explain me the link between the .lproj files, and/or the Localizable.strings file (if those are connected) ?
Or by any chance, if you know where i could see/download an example of an app using localized text?
I've seen the Localizable.strings file with the sample code 'NavBar' (from the doc), but nothing yet about a sample code using .lproj files.
Thanks for your help
It's very simple: create a folder for each localization, with the localization name followed by ".lproj", there you put any localizable file (you can also localize images) and your Localizable.strings (which contains the text returned by the obj-c API for localization). Don't forget to add the files in your resources, in Xcode.
For exemple, if you have 3 localizations, you could have this structure:
PROJECT_DIR/
- en.lproj/
Localizable.strings
- it.lproj/
Localizable.strings
- pt.lproj/
Localizable.strings
en.lproj/Localizable.strings have the english strings, and so on. Add the three Localizable.strings on your Xcode (it will be smart enough to group then) and it's done.
To use the localized strings just call NSLocalizedString(NSString *key, NSString *comment), it will automatically look for the key in your Localizable.strings file for the current locale and return the value associated with the key. For more information about NSLocalizedString see NSLocalizedString.

Custom fonts on iOS app - working in Simulator but not iPad

Encountering a weird problem here. I'm developing a game for my school project (non-commercial), and I'm using a custom font Black Chancery (free under GNU GPL). I followed the instructions from multiple sources, which includes:
Add the font to the project (TTF).
Modify app-Info.plist to add the font to it ("Fonts provided by application").
Using [UIFont fontWithName:#"BlackChancery" size:30] when the font is needed.
I could get the font displayed in the Simulator, however when I load it into my iPad, the default system font is used. I'm pretty sure there isn't a problem with the font itself as it displays in the simulator, and I've used FontForge to open the font without any warnings (following from This Question).
Any help is greatly appreciated. Thanks! :)
I can only guess as you haven't posted the contents of your plist or a directory listing of the bundle, but many cases of "resource works on the simulator but not on the device" are caused by the fact that the OS X filesystem is normally configured to be case-insensitive while the filesystem on the device is case sensitive. For example, if your file is named "BlackChancery.TTF" and your plist refers to it as "BlackChancery.ttf", it will be found on the simulator but not on the device.
I was having problem with font not recognizing, I fixed it by checking the correct name of the font by checking info of the font file by Get Info option. In my case the file name was written xyzfont.ttf but actually it was XyzFont.TTF in the info, i replaced and it worked.
Hope, it helps someone.
Another Way
I have come across one more way of finding the correct name, is by installing the font in the FontBook..
Just open FontBook from Finder and select User now from File->Add Fonts select the font you want to add into your application, after little processing the FontBook will show the Font listed in with the Correct name, use the name in the FontBook ignoring the actual ttf file name you have imported or, added to plist.. It should work..
I had the same problem which was resolved with a slight variation on iphonc's solution. The case sensitivity was directly related to the file extension. The problem was associated with my font file named: Choc.TTF
I had to remove the reference to the file in xCode 4.1
Rename the file to Choc.ttf (note lower case file extension)
Add the reference back into xCode
Perform a clean and re-build for the device
Conclusion (in my particular case):
Case sensitivity applies not JUST to the file name, but to the file extension as well (i.e. iOS device appears to tolerate only lower case).
My answer is different from all the rest. I had a problem because the font was all one word and lowercase "compassnormal.ttf" and the name in the file was Compass. So, my code was:
[UIFont fontWithName:#"Compass" size:24]]
Bundle Resource said:
compassnormal.ttf
~info.plist said:
compassnormal.ttf
None of this worked until I changed the actual filename to match it's official name in fontbook.
deleted all references from Bundle Resources and ~info.plist;
added font with updated name to Bundle Resources;
updated plist with new name;
tested in simulator and on device, Voila!
I have also experienced a problem with fonts containing the dash (-) character. Remove that character from your font names and try with that.
So your font named Gotham-Black.ttf should be named GothamBlack.ttf
Also check that your fonts are not zero bytes. I had this same issue and it turned out that my font files had emptied themselves at some stage. Probably when rearranging them in XCode and AppCode.
You have to use the real font name in the [UIFont fontWithName:#"... method! Not the ttf filename!!!
This real name is mostly far away from the filename. Just open the rtf in the Mac font utility. In the header you see the font family!!! Only the family!!! if you now use
NSArray *fontNames = [UIFont fontNamesForFamilyName:#"MyFontNameFamily"];
NSLog(#"%#", fontNames);
in your code, you get the real real real name in the console ;-)
But in the plist entry you still need the (case sensitive) filename!!!
I have the same issue on Xcode 6. My file name was My Font.ttf, it doesn't work. I manage to make it works when I rename it to My Font.TTF, just change the file extension to uppercase.