Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocalizedString "localizedStringForKey:value:table:"

- (NSString *)localizedStringForKey:(NSString *)key 
                              value:(NSString *)value 
                              table:(NSString *)tableName

Doc says about the tableName argument in the above method as: The receiver’s string table to search. If tableName is nil or is an empty string, the method attempts to use the table in Localizable.strings...

My question is if we create a Localizable.strings it creates a string file alone. No tables are created in our project. Where is the table actually? Is it possible to create such string tables manually? I have a need to do that in my project...

And my final question is - What value I have pass as the argument to the tableName parameter?

Thank you...

like image 813
EmptyStack Avatar asked May 24 '11 12:05

EmptyStack


2 Answers

In that context, "table" refers to the file of translations. So for Localizable.strings, you can get translations from it with NSLocalizedStringFromTable(@"foo", @"Localizable", @"comment"). Localizable.strings is the default, however, so you'd typically just use NSLocalizedString(@"foo", @"comment"). If you add a new translation file (say, Settings.strings), then you'd have use the table name to refer to it.

like image 108
Jonathan del Strother Avatar answered Sep 20 '22 13:09

Jonathan del Strother


By table - it just means a key-value pair.

There is more detail in the documentation

So yes - you have to create these manually - since you are using the NSBundle helper methods for localised strings - you can use - (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName and then run genstrings to generate the .strings file and the tables.

Edited to make this clearer The Strings table is just a list of key value pairs. If you generate a Localizable.strings file that contains this:

/* Text for saying hello */
"HelloText" = "Hello!";

Now you can copy this file to another localised .lproj file and change it to the values for the particular language:

"HelloText" = "Namaste!";

That's all they mean by a table.

like image 30
Abizern Avatar answered Sep 19 '22 13:09

Abizern