i found this good example to use NSLocalizedString : What is the second parameter of NSLocalizedString()?
NSLocalizedString(#"Save",#"Title of the Save button in the theme saving dialog");
.
/* Title of the Save button in the theme saving dialog */
"Save" = "Save";
But what if the comment in NSLocalizedString is empty ?what does is mean? Will it automatically know where to find the translated word in localize.strings?
Thanks
The comment is reserved for the genstrings tool to help someone, who may or may not be technical, translate your localized strings into new languages.
The first parameter is the key into localizable.strings. The second parameter is a comment meant to assist in translation. It won't effect the behavior of the application at all, so it doesn't strictly matter if it's empty or nil.
Related
In Localizable.strings file, why is it necessary to put placeholders in the key.
Assuming you use a dot notation like;
"welcome-back.label" = "welcome back, %#"
I've seen examples where they mix placeholders and dot notation something like this;
"welcome-back %#.label" = "welcome back, %#"
^ The above might be incorrect.
But what I don't understand is why you even need the placeholder at all in the key when its just a pointer to a value.
Can someone shed light on this?
Many thanks
You don't need it in the key, it's there to make life easier for people who read the code in the future so they can easily tell that a parameter should be passed, what it's for and therefore which variable should be used. If you want to use some other specification to indicate this that's fine. If you want to make it super terse and hard to use that's also fine, just discouraged...
NSLocalizedString will replace the string on the left hand side with the string on the right hand side. The string on the right hand side must obviously be the correct string for the situation, the string on the left hand side can be anything you want. You could use keys "1", "2", "3" etc and it would work (although you would go mad).
You can improve your life as a developer with the right strategies. I tend to never use plain english text as the key, because the same English word can have many different translations (for example "key" in German can be Taste, Schlüssel, Tonart and lots of other things). Instead I write some text that describes what the text is used for.
And to avoid problems when you type in the key incorrectly, which the compiler has no chance to find, I tend to use #define statements for the keys. Much easier to keep just a list of #defines and your localizable.strings in sync, and the compiler will tell you if you misspell a #defined constant.
And I tend to use the word "format" for strings that are format strings and not used directly. So I might have in one header file
#define kWelcomeBackLabelTitleFormat #"WelcomeBackLabelTitleFormat"
and in the localizable.strings file
"WelcomeBackLabelTitleFormat" = "welcome back, %#";
(The #define saves you if you used "WelcomebackLabelTitleFormat" by mistake with a lowercase b).
I have a problem to strip out the format in a note table
Here is an example:
";\red31\green73\blue125;
\viewkind4\uc1\ltrpar\f0\fs20 USEFUL TEXT BODY \cf1\f3
\ltrpar\f0\fs17
"
How to get rid of those stuff? I want to play safe not to replace anything after'\'
Many thanks,
Rick
Your making it quite difficult for yourself by not replace '\' .
If you look at http://other9.tripod.com/Refs/easy-rtf.html you will see that there are different RTF codes and there is no default size for the codes.
Additionally, it is not like HTML where there must be a necessary "closing" tag which makes it additionally difficult.
The only thing I can think of is to record all possible RTF codes (or use an RTF parser library) and hence be able to recognize if a \ is or is not RTF code.
There are so many settings in the preferences for Code->Style->Objective-C. I'm looking for the right one to reformat this line of code
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at" title:#"Tweeted At" type:SCPropertyTypeLabel];
to this format
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at"
title:#"Tweeted At"
type:SCPropertyTypeLabel];
(the point is to have the colons indention matching)
I guess the it should be in the Wrapping and Braces Tab, but I havn't found the right setting yet.
Thanks for your ideas.
The setting you are looking for is Wrapping and Braces | Method call arguments set to Chop down if long with enabled Align by colon. Note that there are separate settings for Method parameters.
It seems like as of App Code 2017.1 (perhaps earlier too) the align by colon option is not available in Swift. You can still tell App Code to chop a long argument/parameter list:
I'm a newbie in objective c.
I want to know what's the most common way to handle messages(or string format) in a xcode project.I mean, to put all the message strings or formats in one file to manage it easily.
Could anyone give me some advice??
Thanks~
Have you looked at localization options? It is usually a good idea to prepare your app or program for internationalization. The way this works is to have a file Localizable.strings where you have the exact text defined for each "text macro". The strings files (you have a version for each language) are in a very simple format:
// in en.lproj
"Hello" = "Hello, World!";
// in de.lproj
"Hello" = "Hallo, Welt!"
Just make sure in your code you consistently use this format for literal strings that are displayed anywhere in your user interface:
label.text = NSLocalizedString(#"Hello", #"Optional comment");
I am creating a program and I need to validate my text boxes. For the program the user needs to put in a phrase. But I am not sure how to make sure that the user actually entered in a phrase, the phrase isn't (ex.) skldkfdl, or that there isn't a space.
Strings in Java
You could do a String.Trim() to get rid of trailing whitespaces first...
then do a String.IndexOf(" ") to check for a space.
If the function returns -1, it means there is no space in the string.
Running on the assumption that you're using VB.Net - Add an event handler for the event where you want to validate the text, such as when a "Submit" button is clicked. You may want to use a CancelEventHandler, so that you can cancel the click.
In the event handler, if you're looking for just simple validation, you can use if-statements to check some simple conditions, such as if you just want to check "if input.equals(password)".
Look here for an example of using CancelEventHandler
If you're looking for some more complex validation, you'll want to use regular expressions.
This page might help get you started
Checking to see if something is "a phrase", as in, proper English, would be very difficult. You would need to make sure that all of the words are in the dictionary, and then you would need to check for proper grammar, which is incredibly complex, given English grammar rules. You may want to simplify your approach, depending on your problem. For example, maybe just check that no weird characters are used, that there is more than one space, and that each word contains a vowel.